hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.74k stars 9.1k forks source link

[Bug]: enable_auto_sub_domain does not work with new amplify 2.0 #37498

Open slava-gls opened 4 months ago

slava-gls commented 4 months ago

Terraform Core Version

1.8.3

AWS Provider Version

5.49.0

Affected Resource(s)

aws_amplify_domain_association

Expected Behavior

enable_auto_sub_domain should enable auto subdomain creation on the amplify side.

Actual Behavior

Even when enable_auto_sub_domain set to true, the option is not enabled on the amplify side, most probably because AutoSubDomainCreationPatterns option is not set. It's also impossible now to enable auto subdomain creation from aws console without providing creation pattern together with it

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

resource "aws_amplify_domain_association" "domain_association" {
  app_id      = aws_amplify_app.*.id
  domain_name = var.react_app_app_host_domain
  enable_auto_sub_domain = true
  wait_for_verification = false
}

Steps to Reproduce

  1. Set enable_auto_sub_domain=true
  2. Apply plan
  3. Observe, that sub domains auto creation option is not enabled in aws console

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

No

github-actions[bot] commented 4 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

aidenvaines-bjss commented 1 month ago

I too am experiencing this issue having had issues with branches not registering custom DNS entries.

Returning to the AWS CLI both the working state and problem described in this bug can be emulated.

Correct configuration: aws amplify create-domain-association --app-id xxx --domain-name correct.xx.xx.xx.xx --sub-domain-settings prefix="",branchName="main" --enable-auto-sub-domain --auto-sub-domain-creation-patterns "*"

Incorrect configuration: aws amplify create-domain-association --app-id xxx --domain-name incorrect.xx.xx.xx.xx --sub-domain-settings prefix="",branchName="main" --enable-auto-sub-domain

With the correct configuration the domain configuration will show "" in the subdomains pattern field. The incorrect one, where the autoSubDomainCreationPaterns field is skipped will have ", pr*". Despite the help text for the field stating "Enter comma separated values for multiple patterns" this doesn't work. However, if you pull the actual config from the API you'll see the problem:

With the 'Correct configuration' set the get-domain-association command will return

    "domainAssociation": {
        ......
        "enableAutoSubDomain": true,
        "autoSubDomainCreationPatterns": [
            "*"
        ],
        "domainSta.....

With the 'Incorrect configuration' or using the terraform aws_amplify_domain_association

    "domainAssociation": {
        "...
        "enableAutoSubDomain": true,
        "domainSta....

The autoSubDomainCreationPatterns field is totally missing from the response but the web console clearly shows image Iit seems that ", pr" in the web UI is just placeholder text with zero impact.

There also seems to be an issue with this: https://docs.aws.amazon.com/amplify/latest/userguide/wildcard-subdomain-support.html where by having the root as the only subdomain setup causes the certificates and configuration to not include the wildcard, so any subsequent branches added try to register against the root domain rather than creating a subdomain

My work around for this is a bit annoying and looks like this:

  triggers = {
    amplify_app_id      = aws_amplify_app.main.id
    amplify_branch_name = module.amplify_branch.name
    amplify_domain_name = local.acct.dns_zone["name"]
  }

  provisioner "local-exec" {
    when    = create
    command = "aws amplify create-domain-association --app-id ${self.triggers.amplify_app_id} --domain-name ${self.triggers.amplify_domain_name} --sub-domain-settings prefix=\"\",branchName=\"${self.triggers.amplify_branch_name}\" prefix=\"${self.triggers.amplify_branch_name}\",branchName=\"${self.triggers.amplify_branch_name}\" --enable-auto-sub-domain --auto-sub-domain-creation-patterns \"*,pr*\""
  }

  provisioner "local-exec" {
    when    = destroy
    command = "aws amplify delete-domain-association --app-id ${self.triggers.amplify_app_id} --domain-name ${self.triggers.amplify_domain_name}"
  }
}

I found that just including "*" with the sub domain creation patterns didnt work, it needed both "*"and "pr*"