Terraform with API-Gateway, Route53, and SSL Certification interdependency problem2019 Community Moderator ElectionHow to create an SSL AWS API Gateway endpoint with custom domain?How to specify a ACM certificate in a specific region for a data source?Routing to API gateway using AWS Route 53Using custom domain for aws api gateway endpoint in mumbaiaws cloudfront api endpoint responding with Forbidden(403)AWS API gateway High Availability setup in us-east-1 and us-east-2API Gateway - Invalid certificate chain when using regional and custom domain namesAPI Gateway + GovCloud + Custom Domain Name with SSL CertTerraform AWS ACM certificates in us-east-1 for resources in eu-west-1Custom domain name for API Gateway terraform

How to explain that I do not want to visit a country due to personal safety concern?

How to terminate ping <dest> &

Employee lack of ownership

Why do passenger jet manufacturers design their planes with stall prevention systems?

Why doesn't using two cd commands in bash script execute the second command?

How Could an Airship Be Repaired Mid-Flight

If I can solve Sudoku can I solve Travelling Salesman Problem(TSP)? If yes, how?

Why do Australian milk farmers need to protest supermarkets' milk price?

Why doesn't the EU now just force the UK to choose between referendum and no-deal?

Interplanetary conflict, some disease destroys the ability to understand or appreciate music

How to deal with taxi scam when on vacation?

Is a party consisting of only a bard, a cleric, and a warlock functional long-term?

What options are left, if Britain cannot decide?

Dice rolling probability game

Existence of subset with given Hausdorff dimension

How to make healing in an exploration game interesting

What's the meaning of “spike” in the context of “adrenaline spike”?

how to write formula in word in latex

How to use deus ex machina safely?

Professor being mistaken for a grad student

A Cautionary Suggestion

Is it possible to upcast ritual spells?

Can I use USB data pins as power source

Most cost effective thermostat setting: consistent temperature vs. lowest temperature possible



Terraform with API-Gateway, Route53, and SSL Certification interdependency problem



2019 Community Moderator ElectionHow to create an SSL AWS API Gateway endpoint with custom domain?How to specify a ACM certificate in a specific region for a data source?Routing to API gateway using AWS Route 53Using custom domain for aws api gateway endpoint in mumbaiaws cloudfront api endpoint responding with Forbidden(403)AWS API gateway High Availability setup in us-east-1 and us-east-2API Gateway - Invalid certificate chain when using regional and custom domain namesAPI Gateway + GovCloud + Custom Domain Name with SSL CertTerraform AWS ACM certificates in us-east-1 for resources in eu-west-1Custom domain name for API Gateway terraform










2















I can't seem to get an SSL certificate from ACM working on API-Gateway, Route53, using terraform. There seems to be an interdependency problem.



data "aws_route53_zone" "root_domain" 
name = "$var.route53_root_domain_name"
private_zone = false


# The domain name to use with api-gateway
resource "aws_api_gateway_domain_name" "domain_name"
domain_name = "$var.route53_sub_domain_name"

certificate_arn = "$aws_acm_certificate.cert.arn"


resource "aws_route53_record" "sub_domain"
name = "$var.route53_sub_domain_name"
type = "A"
zone_id = "$data.aws_route53_zone.root_domain.zone_id"

alias
name = "$aws_api_gateway_domain_name.domain_name.cloudfront_domain_name"
zone_id = "$aws_api_gateway_domain_name.domain_name.cloudfront_zone_id"
evaluate_target_health = false



resource "aws_acm_certificate" "cert"
# api-gateway / cloudfront certificates need to use the us-east-1 region
provider = "aws.cloudfront-acm-certs"
domain_name = "$var.route53_sub_domain_name"
validation_method = "DNS"

lifecycle
create_before_destroy = true



resource "aws_route53_record" "cert_validation"
name = "$aws_acm_certificate.cert.domain_validation_options.0.resource_record_name"
type = "$aws_acm_certificate.cert.domain_validation_options.0.resource_record_type"
zone_id = "$aws_route53_record.sub_domain.zone_id"
records = ["$aws_acm_certificate.cert.domain_validation_options.0.resource_record_value"]
ttl = 60


resource "aws_acm_certificate_validation" "cert"
# api-gateway / cloudfront certificates need to use the us-east-1 region
provider = "aws.cloudfront-acm-certs"

certificate_arn = "$aws_acm_certificate.cert.arn"
validation_record_fqdns = ["$aws_route53_record.cert_validation.fqdn"]



The problem appears to be that:



  1. aws_api_gateway_domain_name requires aws_acm_certificate

  2. aws_acm_certificate has to be validated, so step 3

  3. aws_route53_record.cert_validation requires aws_route53_record.sub_domain

  4. aws_route53_record.subdomain requires aws_api_gateway_domain_name

  5. Go to 1

Everytime I try to use the configuration given, I get the following error:




aws_api_gateway_domain_name.domain_name: Error creating API Gateway
Domain Name: BadRequestException: Unable to associate certificate
arn:aws:acm:us-east-1:yyyy:certificate/zzzz with CloudFront. This
error may prevent the domain name audit-log.taspli.com from being used
in API Gateway for up to 40 minutes. Please ensure the certificate
domain name matches the requested domain name, and that this user has
permission to call cloudfront:UpdateDistribution on '*' resources.
status code: 400, request id: xxxx











share|improve this question






















  • 3. aws_route53_record.cert_validation requires aws_route53_record.sub_domain is false. It only requires the validation records, not the record for the subdomain that is the subject of the certificate. You can prove this for yourself by manually creating an DNS-validated ACM cert for a nonexistent subdomain in a working Route 53 hosted zone. The error message suggests only that the cert has not yet been validated, not that validation can't/won't succeed.

    – Michael - sqlbot
    Mar 7 at 9:33












  • ah, so I can remove the zone_id field and then it'll succeed anyway? How would it know where to add the record as it's parent if not the domain I'm creating it on?

    – Christopher Thomas
    Mar 7 at 9:35











  • ok, so I validated my claim that the aws_route53_record for cert validation requires the zone_id. Therefore the zone the records are being attached to have to exist first before it can attach the records. This makes sense. The problem then is that the aws_route53_record for the sub domain where it's being attached needs the records from the api gateway domain name in order to attach the alias to the cloudfront distribution that api gateway creates. So again, it's just another cyclic dependency that I'm unsure how to resolve.

    – Christopher Thomas
    Mar 7 at 9:56















2















I can't seem to get an SSL certificate from ACM working on API-Gateway, Route53, using terraform. There seems to be an interdependency problem.



data "aws_route53_zone" "root_domain" 
name = "$var.route53_root_domain_name"
private_zone = false


# The domain name to use with api-gateway
resource "aws_api_gateway_domain_name" "domain_name"
domain_name = "$var.route53_sub_domain_name"

certificate_arn = "$aws_acm_certificate.cert.arn"


resource "aws_route53_record" "sub_domain"
name = "$var.route53_sub_domain_name"
type = "A"
zone_id = "$data.aws_route53_zone.root_domain.zone_id"

alias
name = "$aws_api_gateway_domain_name.domain_name.cloudfront_domain_name"
zone_id = "$aws_api_gateway_domain_name.domain_name.cloudfront_zone_id"
evaluate_target_health = false



resource "aws_acm_certificate" "cert"
# api-gateway / cloudfront certificates need to use the us-east-1 region
provider = "aws.cloudfront-acm-certs"
domain_name = "$var.route53_sub_domain_name"
validation_method = "DNS"

lifecycle
create_before_destroy = true



resource "aws_route53_record" "cert_validation"
name = "$aws_acm_certificate.cert.domain_validation_options.0.resource_record_name"
type = "$aws_acm_certificate.cert.domain_validation_options.0.resource_record_type"
zone_id = "$aws_route53_record.sub_domain.zone_id"
records = ["$aws_acm_certificate.cert.domain_validation_options.0.resource_record_value"]
ttl = 60


resource "aws_acm_certificate_validation" "cert"
# api-gateway / cloudfront certificates need to use the us-east-1 region
provider = "aws.cloudfront-acm-certs"

certificate_arn = "$aws_acm_certificate.cert.arn"
validation_record_fqdns = ["$aws_route53_record.cert_validation.fqdn"]



The problem appears to be that:



  1. aws_api_gateway_domain_name requires aws_acm_certificate

  2. aws_acm_certificate has to be validated, so step 3

  3. aws_route53_record.cert_validation requires aws_route53_record.sub_domain

  4. aws_route53_record.subdomain requires aws_api_gateway_domain_name

  5. Go to 1

Everytime I try to use the configuration given, I get the following error:




aws_api_gateway_domain_name.domain_name: Error creating API Gateway
Domain Name: BadRequestException: Unable to associate certificate
arn:aws:acm:us-east-1:yyyy:certificate/zzzz with CloudFront. This
error may prevent the domain name audit-log.taspli.com from being used
in API Gateway for up to 40 minutes. Please ensure the certificate
domain name matches the requested domain name, and that this user has
permission to call cloudfront:UpdateDistribution on '*' resources.
status code: 400, request id: xxxx











share|improve this question






















  • 3. aws_route53_record.cert_validation requires aws_route53_record.sub_domain is false. It only requires the validation records, not the record for the subdomain that is the subject of the certificate. You can prove this for yourself by manually creating an DNS-validated ACM cert for a nonexistent subdomain in a working Route 53 hosted zone. The error message suggests only that the cert has not yet been validated, not that validation can't/won't succeed.

    – Michael - sqlbot
    Mar 7 at 9:33












  • ah, so I can remove the zone_id field and then it'll succeed anyway? How would it know where to add the record as it's parent if not the domain I'm creating it on?

    – Christopher Thomas
    Mar 7 at 9:35











  • ok, so I validated my claim that the aws_route53_record for cert validation requires the zone_id. Therefore the zone the records are being attached to have to exist first before it can attach the records. This makes sense. The problem then is that the aws_route53_record for the sub domain where it's being attached needs the records from the api gateway domain name in order to attach the alias to the cloudfront distribution that api gateway creates. So again, it's just another cyclic dependency that I'm unsure how to resolve.

    – Christopher Thomas
    Mar 7 at 9:56













2












2








2








I can't seem to get an SSL certificate from ACM working on API-Gateway, Route53, using terraform. There seems to be an interdependency problem.



data "aws_route53_zone" "root_domain" 
name = "$var.route53_root_domain_name"
private_zone = false


# The domain name to use with api-gateway
resource "aws_api_gateway_domain_name" "domain_name"
domain_name = "$var.route53_sub_domain_name"

certificate_arn = "$aws_acm_certificate.cert.arn"


resource "aws_route53_record" "sub_domain"
name = "$var.route53_sub_domain_name"
type = "A"
zone_id = "$data.aws_route53_zone.root_domain.zone_id"

alias
name = "$aws_api_gateway_domain_name.domain_name.cloudfront_domain_name"
zone_id = "$aws_api_gateway_domain_name.domain_name.cloudfront_zone_id"
evaluate_target_health = false



resource "aws_acm_certificate" "cert"
# api-gateway / cloudfront certificates need to use the us-east-1 region
provider = "aws.cloudfront-acm-certs"
domain_name = "$var.route53_sub_domain_name"
validation_method = "DNS"

lifecycle
create_before_destroy = true



resource "aws_route53_record" "cert_validation"
name = "$aws_acm_certificate.cert.domain_validation_options.0.resource_record_name"
type = "$aws_acm_certificate.cert.domain_validation_options.0.resource_record_type"
zone_id = "$aws_route53_record.sub_domain.zone_id"
records = ["$aws_acm_certificate.cert.domain_validation_options.0.resource_record_value"]
ttl = 60


resource "aws_acm_certificate_validation" "cert"
# api-gateway / cloudfront certificates need to use the us-east-1 region
provider = "aws.cloudfront-acm-certs"

certificate_arn = "$aws_acm_certificate.cert.arn"
validation_record_fqdns = ["$aws_route53_record.cert_validation.fqdn"]



The problem appears to be that:



  1. aws_api_gateway_domain_name requires aws_acm_certificate

  2. aws_acm_certificate has to be validated, so step 3

  3. aws_route53_record.cert_validation requires aws_route53_record.sub_domain

  4. aws_route53_record.subdomain requires aws_api_gateway_domain_name

  5. Go to 1

Everytime I try to use the configuration given, I get the following error:




aws_api_gateway_domain_name.domain_name: Error creating API Gateway
Domain Name: BadRequestException: Unable to associate certificate
arn:aws:acm:us-east-1:yyyy:certificate/zzzz with CloudFront. This
error may prevent the domain name audit-log.taspli.com from being used
in API Gateway for up to 40 minutes. Please ensure the certificate
domain name matches the requested domain name, and that this user has
permission to call cloudfront:UpdateDistribution on '*' resources.
status code: 400, request id: xxxx











share|improve this question














I can't seem to get an SSL certificate from ACM working on API-Gateway, Route53, using terraform. There seems to be an interdependency problem.



data "aws_route53_zone" "root_domain" 
name = "$var.route53_root_domain_name"
private_zone = false


# The domain name to use with api-gateway
resource "aws_api_gateway_domain_name" "domain_name"
domain_name = "$var.route53_sub_domain_name"

certificate_arn = "$aws_acm_certificate.cert.arn"


resource "aws_route53_record" "sub_domain"
name = "$var.route53_sub_domain_name"
type = "A"
zone_id = "$data.aws_route53_zone.root_domain.zone_id"

alias
name = "$aws_api_gateway_domain_name.domain_name.cloudfront_domain_name"
zone_id = "$aws_api_gateway_domain_name.domain_name.cloudfront_zone_id"
evaluate_target_health = false



resource "aws_acm_certificate" "cert"
# api-gateway / cloudfront certificates need to use the us-east-1 region
provider = "aws.cloudfront-acm-certs"
domain_name = "$var.route53_sub_domain_name"
validation_method = "DNS"

lifecycle
create_before_destroy = true



resource "aws_route53_record" "cert_validation"
name = "$aws_acm_certificate.cert.domain_validation_options.0.resource_record_name"
type = "$aws_acm_certificate.cert.domain_validation_options.0.resource_record_type"
zone_id = "$aws_route53_record.sub_domain.zone_id"
records = ["$aws_acm_certificate.cert.domain_validation_options.0.resource_record_value"]
ttl = 60


resource "aws_acm_certificate_validation" "cert"
# api-gateway / cloudfront certificates need to use the us-east-1 region
provider = "aws.cloudfront-acm-certs"

certificate_arn = "$aws_acm_certificate.cert.arn"
validation_record_fqdns = ["$aws_route53_record.cert_validation.fqdn"]



The problem appears to be that:



  1. aws_api_gateway_domain_name requires aws_acm_certificate

  2. aws_acm_certificate has to be validated, so step 3

  3. aws_route53_record.cert_validation requires aws_route53_record.sub_domain

  4. aws_route53_record.subdomain requires aws_api_gateway_domain_name

  5. Go to 1

Everytime I try to use the configuration given, I get the following error:




aws_api_gateway_domain_name.domain_name: Error creating API Gateway
Domain Name: BadRequestException: Unable to associate certificate
arn:aws:acm:us-east-1:yyyy:certificate/zzzz with CloudFront. This
error may prevent the domain name audit-log.taspli.com from being used
in API Gateway for up to 40 minutes. Please ensure the certificate
domain name matches the requested domain name, and that this user has
permission to call cloudfront:UpdateDistribution on '*' resources.
status code: 400, request id: xxxx








amazon-web-services aws-api-gateway terraform amazon-route53 terraform-provider-aws






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 6 at 19:52









Christopher ThomasChristopher Thomas

2,25022231




2,25022231












  • 3. aws_route53_record.cert_validation requires aws_route53_record.sub_domain is false. It only requires the validation records, not the record for the subdomain that is the subject of the certificate. You can prove this for yourself by manually creating an DNS-validated ACM cert for a nonexistent subdomain in a working Route 53 hosted zone. The error message suggests only that the cert has not yet been validated, not that validation can't/won't succeed.

    – Michael - sqlbot
    Mar 7 at 9:33












  • ah, so I can remove the zone_id field and then it'll succeed anyway? How would it know where to add the record as it's parent if not the domain I'm creating it on?

    – Christopher Thomas
    Mar 7 at 9:35











  • ok, so I validated my claim that the aws_route53_record for cert validation requires the zone_id. Therefore the zone the records are being attached to have to exist first before it can attach the records. This makes sense. The problem then is that the aws_route53_record for the sub domain where it's being attached needs the records from the api gateway domain name in order to attach the alias to the cloudfront distribution that api gateway creates. So again, it's just another cyclic dependency that I'm unsure how to resolve.

    – Christopher Thomas
    Mar 7 at 9:56

















  • 3. aws_route53_record.cert_validation requires aws_route53_record.sub_domain is false. It only requires the validation records, not the record for the subdomain that is the subject of the certificate. You can prove this for yourself by manually creating an DNS-validated ACM cert for a nonexistent subdomain in a working Route 53 hosted zone. The error message suggests only that the cert has not yet been validated, not that validation can't/won't succeed.

    – Michael - sqlbot
    Mar 7 at 9:33












  • ah, so I can remove the zone_id field and then it'll succeed anyway? How would it know where to add the record as it's parent if not the domain I'm creating it on?

    – Christopher Thomas
    Mar 7 at 9:35











  • ok, so I validated my claim that the aws_route53_record for cert validation requires the zone_id. Therefore the zone the records are being attached to have to exist first before it can attach the records. This makes sense. The problem then is that the aws_route53_record for the sub domain where it's being attached needs the records from the api gateway domain name in order to attach the alias to the cloudfront distribution that api gateway creates. So again, it's just another cyclic dependency that I'm unsure how to resolve.

    – Christopher Thomas
    Mar 7 at 9:56
















3. aws_route53_record.cert_validation requires aws_route53_record.sub_domain is false. It only requires the validation records, not the record for the subdomain that is the subject of the certificate. You can prove this for yourself by manually creating an DNS-validated ACM cert for a nonexistent subdomain in a working Route 53 hosted zone. The error message suggests only that the cert has not yet been validated, not that validation can't/won't succeed.

– Michael - sqlbot
Mar 7 at 9:33






3. aws_route53_record.cert_validation requires aws_route53_record.sub_domain is false. It only requires the validation records, not the record for the subdomain that is the subject of the certificate. You can prove this for yourself by manually creating an DNS-validated ACM cert for a nonexistent subdomain in a working Route 53 hosted zone. The error message suggests only that the cert has not yet been validated, not that validation can't/won't succeed.

– Michael - sqlbot
Mar 7 at 9:33














ah, so I can remove the zone_id field and then it'll succeed anyway? How would it know where to add the record as it's parent if not the domain I'm creating it on?

– Christopher Thomas
Mar 7 at 9:35





ah, so I can remove the zone_id field and then it'll succeed anyway? How would it know where to add the record as it's parent if not the domain I'm creating it on?

– Christopher Thomas
Mar 7 at 9:35













ok, so I validated my claim that the aws_route53_record for cert validation requires the zone_id. Therefore the zone the records are being attached to have to exist first before it can attach the records. This makes sense. The problem then is that the aws_route53_record for the sub domain where it's being attached needs the records from the api gateway domain name in order to attach the alias to the cloudfront distribution that api gateway creates. So again, it's just another cyclic dependency that I'm unsure how to resolve.

– Christopher Thomas
Mar 7 at 9:56





ok, so I validated my claim that the aws_route53_record for cert validation requires the zone_id. Therefore the zone the records are being attached to have to exist first before it can attach the records. This makes sense. The problem then is that the aws_route53_record for the sub domain where it's being attached needs the records from the api gateway domain name in order to attach the alias to the cloudfront distribution that api gateway creates. So again, it's just another cyclic dependency that I'm unsure how to resolve.

– Christopher Thomas
Mar 7 at 9:56












1 Answer
1






active

oldest

votes


















0














I seem to have fixed the problem by adding the certificate validation records to the root domain instead of the sub domain. Therefore breaking the cyclic dependency.



The problem appears to be that the sub domain can't be created without the certificate and the certificate can't be validated without the sub domain. So the situation is stuck and unresolvable.



You could manually create the sub domain, but then whats the point in automation if you have to make manual efforts to solve problems.



So I tried adding the cert validation records to the root. Suddenly it starts to work, because the root domain is something that is created externally to the project. A sort of global infrastructure project which can be handled externally. Then your individual projects can hang off of that infrastructure on a case-by-case basis.



Here is the terraform configuration which worked:



data "aws_route53_zone" "root_domain" 
name = "$var.route53_root_domain_name"
private_zone = false


# The domain name to use with api-gateway
resource "aws_api_gateway_domain_name" "domain_name"
domain_name = "$var.route53_sub_domain_name"

certificate_arn = "$aws_acm_certificate.cert.arn"


resource "aws_route53_record" "sub_domain"
name = "$var.route53_sub_domain_name"
type = "A"
zone_id = "$data.aws_route53_zone.root_domain.zone_id"

alias
name = "$aws_api_gateway_domain_name.domain_name.cloudfront_domain_name"
zone_id = "$aws_api_gateway_domain_name.domain_name.cloudfront_zone_id"
evaluate_target_health = false



resource "aws_acm_certificate" "cert"
# api-gateway / cloudfront certificates need to use the us-east-1 region
provider = "aws.cloudfront-acm-certs"
domain_name = "$var.route53_sub_domain_name"
validation_method = "DNS"


resource "aws_route53_record" "cert_validation"
name = "$aws_acm_certificate.cert.domain_validation_options.0.resource_record_name"
type = "$aws_acm_certificate.cert.domain_validation_options.0.resource_record_type"
zone_id = "$data.aws_route53_zone.root_domain.zone_id"
records = ["$aws_acm_certificate.cert.domain_validation_options.0.resource_record_value"]
ttl = 60


resource "aws_acm_certificate_validation" "cert"
# api-gateway / cloudfront certificates need to use the us-east-1 region
provider = "aws.cloudfront-acm-certs"

certificate_arn = "$aws_acm_certificate.cert.arn"
validation_record_fqdns = ["$aws_route53_record.cert_validation.fqdn"]

timeouts
create = "45m"







share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55031167%2fterraform-with-api-gateway-route53-and-ssl-certification-interdependency-probl%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I seem to have fixed the problem by adding the certificate validation records to the root domain instead of the sub domain. Therefore breaking the cyclic dependency.



    The problem appears to be that the sub domain can't be created without the certificate and the certificate can't be validated without the sub domain. So the situation is stuck and unresolvable.



    You could manually create the sub domain, but then whats the point in automation if you have to make manual efforts to solve problems.



    So I tried adding the cert validation records to the root. Suddenly it starts to work, because the root domain is something that is created externally to the project. A sort of global infrastructure project which can be handled externally. Then your individual projects can hang off of that infrastructure on a case-by-case basis.



    Here is the terraform configuration which worked:



    data "aws_route53_zone" "root_domain" 
    name = "$var.route53_root_domain_name"
    private_zone = false


    # The domain name to use with api-gateway
    resource "aws_api_gateway_domain_name" "domain_name"
    domain_name = "$var.route53_sub_domain_name"

    certificate_arn = "$aws_acm_certificate.cert.arn"


    resource "aws_route53_record" "sub_domain"
    name = "$var.route53_sub_domain_name"
    type = "A"
    zone_id = "$data.aws_route53_zone.root_domain.zone_id"

    alias
    name = "$aws_api_gateway_domain_name.domain_name.cloudfront_domain_name"
    zone_id = "$aws_api_gateway_domain_name.domain_name.cloudfront_zone_id"
    evaluate_target_health = false



    resource "aws_acm_certificate" "cert"
    # api-gateway / cloudfront certificates need to use the us-east-1 region
    provider = "aws.cloudfront-acm-certs"
    domain_name = "$var.route53_sub_domain_name"
    validation_method = "DNS"


    resource "aws_route53_record" "cert_validation"
    name = "$aws_acm_certificate.cert.domain_validation_options.0.resource_record_name"
    type = "$aws_acm_certificate.cert.domain_validation_options.0.resource_record_type"
    zone_id = "$data.aws_route53_zone.root_domain.zone_id"
    records = ["$aws_acm_certificate.cert.domain_validation_options.0.resource_record_value"]
    ttl = 60


    resource "aws_acm_certificate_validation" "cert"
    # api-gateway / cloudfront certificates need to use the us-east-1 region
    provider = "aws.cloudfront-acm-certs"

    certificate_arn = "$aws_acm_certificate.cert.arn"
    validation_record_fqdns = ["$aws_route53_record.cert_validation.fqdn"]

    timeouts
    create = "45m"







    share|improve this answer



























      0














      I seem to have fixed the problem by adding the certificate validation records to the root domain instead of the sub domain. Therefore breaking the cyclic dependency.



      The problem appears to be that the sub domain can't be created without the certificate and the certificate can't be validated without the sub domain. So the situation is stuck and unresolvable.



      You could manually create the sub domain, but then whats the point in automation if you have to make manual efforts to solve problems.



      So I tried adding the cert validation records to the root. Suddenly it starts to work, because the root domain is something that is created externally to the project. A sort of global infrastructure project which can be handled externally. Then your individual projects can hang off of that infrastructure on a case-by-case basis.



      Here is the terraform configuration which worked:



      data "aws_route53_zone" "root_domain" 
      name = "$var.route53_root_domain_name"
      private_zone = false


      # The domain name to use with api-gateway
      resource "aws_api_gateway_domain_name" "domain_name"
      domain_name = "$var.route53_sub_domain_name"

      certificate_arn = "$aws_acm_certificate.cert.arn"


      resource "aws_route53_record" "sub_domain"
      name = "$var.route53_sub_domain_name"
      type = "A"
      zone_id = "$data.aws_route53_zone.root_domain.zone_id"

      alias
      name = "$aws_api_gateway_domain_name.domain_name.cloudfront_domain_name"
      zone_id = "$aws_api_gateway_domain_name.domain_name.cloudfront_zone_id"
      evaluate_target_health = false



      resource "aws_acm_certificate" "cert"
      # api-gateway / cloudfront certificates need to use the us-east-1 region
      provider = "aws.cloudfront-acm-certs"
      domain_name = "$var.route53_sub_domain_name"
      validation_method = "DNS"


      resource "aws_route53_record" "cert_validation"
      name = "$aws_acm_certificate.cert.domain_validation_options.0.resource_record_name"
      type = "$aws_acm_certificate.cert.domain_validation_options.0.resource_record_type"
      zone_id = "$data.aws_route53_zone.root_domain.zone_id"
      records = ["$aws_acm_certificate.cert.domain_validation_options.0.resource_record_value"]
      ttl = 60


      resource "aws_acm_certificate_validation" "cert"
      # api-gateway / cloudfront certificates need to use the us-east-1 region
      provider = "aws.cloudfront-acm-certs"

      certificate_arn = "$aws_acm_certificate.cert.arn"
      validation_record_fqdns = ["$aws_route53_record.cert_validation.fqdn"]

      timeouts
      create = "45m"







      share|improve this answer

























        0












        0








        0







        I seem to have fixed the problem by adding the certificate validation records to the root domain instead of the sub domain. Therefore breaking the cyclic dependency.



        The problem appears to be that the sub domain can't be created without the certificate and the certificate can't be validated without the sub domain. So the situation is stuck and unresolvable.



        You could manually create the sub domain, but then whats the point in automation if you have to make manual efforts to solve problems.



        So I tried adding the cert validation records to the root. Suddenly it starts to work, because the root domain is something that is created externally to the project. A sort of global infrastructure project which can be handled externally. Then your individual projects can hang off of that infrastructure on a case-by-case basis.



        Here is the terraform configuration which worked:



        data "aws_route53_zone" "root_domain" 
        name = "$var.route53_root_domain_name"
        private_zone = false


        # The domain name to use with api-gateway
        resource "aws_api_gateway_domain_name" "domain_name"
        domain_name = "$var.route53_sub_domain_name"

        certificate_arn = "$aws_acm_certificate.cert.arn"


        resource "aws_route53_record" "sub_domain"
        name = "$var.route53_sub_domain_name"
        type = "A"
        zone_id = "$data.aws_route53_zone.root_domain.zone_id"

        alias
        name = "$aws_api_gateway_domain_name.domain_name.cloudfront_domain_name"
        zone_id = "$aws_api_gateway_domain_name.domain_name.cloudfront_zone_id"
        evaluate_target_health = false



        resource "aws_acm_certificate" "cert"
        # api-gateway / cloudfront certificates need to use the us-east-1 region
        provider = "aws.cloudfront-acm-certs"
        domain_name = "$var.route53_sub_domain_name"
        validation_method = "DNS"


        resource "aws_route53_record" "cert_validation"
        name = "$aws_acm_certificate.cert.domain_validation_options.0.resource_record_name"
        type = "$aws_acm_certificate.cert.domain_validation_options.0.resource_record_type"
        zone_id = "$data.aws_route53_zone.root_domain.zone_id"
        records = ["$aws_acm_certificate.cert.domain_validation_options.0.resource_record_value"]
        ttl = 60


        resource "aws_acm_certificate_validation" "cert"
        # api-gateway / cloudfront certificates need to use the us-east-1 region
        provider = "aws.cloudfront-acm-certs"

        certificate_arn = "$aws_acm_certificate.cert.arn"
        validation_record_fqdns = ["$aws_route53_record.cert_validation.fqdn"]

        timeouts
        create = "45m"







        share|improve this answer













        I seem to have fixed the problem by adding the certificate validation records to the root domain instead of the sub domain. Therefore breaking the cyclic dependency.



        The problem appears to be that the sub domain can't be created without the certificate and the certificate can't be validated without the sub domain. So the situation is stuck and unresolvable.



        You could manually create the sub domain, but then whats the point in automation if you have to make manual efforts to solve problems.



        So I tried adding the cert validation records to the root. Suddenly it starts to work, because the root domain is something that is created externally to the project. A sort of global infrastructure project which can be handled externally. Then your individual projects can hang off of that infrastructure on a case-by-case basis.



        Here is the terraform configuration which worked:



        data "aws_route53_zone" "root_domain" 
        name = "$var.route53_root_domain_name"
        private_zone = false


        # The domain name to use with api-gateway
        resource "aws_api_gateway_domain_name" "domain_name"
        domain_name = "$var.route53_sub_domain_name"

        certificate_arn = "$aws_acm_certificate.cert.arn"


        resource "aws_route53_record" "sub_domain"
        name = "$var.route53_sub_domain_name"
        type = "A"
        zone_id = "$data.aws_route53_zone.root_domain.zone_id"

        alias
        name = "$aws_api_gateway_domain_name.domain_name.cloudfront_domain_name"
        zone_id = "$aws_api_gateway_domain_name.domain_name.cloudfront_zone_id"
        evaluate_target_health = false



        resource "aws_acm_certificate" "cert"
        # api-gateway / cloudfront certificates need to use the us-east-1 region
        provider = "aws.cloudfront-acm-certs"
        domain_name = "$var.route53_sub_domain_name"
        validation_method = "DNS"


        resource "aws_route53_record" "cert_validation"
        name = "$aws_acm_certificate.cert.domain_validation_options.0.resource_record_name"
        type = "$aws_acm_certificate.cert.domain_validation_options.0.resource_record_type"
        zone_id = "$data.aws_route53_zone.root_domain.zone_id"
        records = ["$aws_acm_certificate.cert.domain_validation_options.0.resource_record_value"]
        ttl = 60


        resource "aws_acm_certificate_validation" "cert"
        # api-gateway / cloudfront certificates need to use the us-east-1 region
        provider = "aws.cloudfront-acm-certs"

        certificate_arn = "$aws_acm_certificate.cert.arn"
        validation_record_fqdns = ["$aws_route53_record.cert_validation.fqdn"]

        timeouts
        create = "45m"








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 10 at 10:04









        Christopher ThomasChristopher Thomas

        2,25022231




        2,25022231





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55031167%2fterraform-with-api-gateway-route53-and-ssl-certification-interdependency-probl%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved