Open vomitHatSteve opened 1 year ago
Voting for Prioritization
Volunteering to Work on This Issue
The Terraform documentation does describe this as an invalid configuration (https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record#alias) But the AWS documentation (https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-api-gateway.html) does not.
The linked documentation doesn't say that this is a valid configuration. It only discusses what happens when you use the AWS Console, which often diverges from the actual underlying API to make things easier.
In this case, the console is aware of the predefined API Gateway zone IDs and just sets them on your behalf.
The relevant reference is the AliasTarget object in the Route53 API reference, which documents HostedZoneId
as a required field, and explains the value that should be used for different types of target, including API Gateway.
The situation here is similar to with load balancers, there is a set of predefined zone IDs (one per region) that are used for aliasing to the service.
You can get the zone ID using the AWS CLI with aws apigateway get-domain-names
or aws apigatewayv2 get-domain-names
or from the Amazon API Gateway endpoints and quotas page in the AWS documentation.
It's also available as the cloudfront_zone_id
(for edge-optimized) and regional_zone_id
(for regional) output attributes on the api_gateway_domain_name
resource. Seems missing on the v2 resources, unless I'm missing it.
Ah yep. You are correct. Thank you for clarifying.
I'm not using an api_gateway_domain_name (or the v2 equivalent) for this, so it's not relevant to my case, but I suppose if the zone_id fields are missing from the v2 version, that might be worth bugging.
From some more research, I have found that the *.amazonaws.com zones are consistent and don't appear to be explicitly exposed by any API. But they are documented: https://docs.aws.amazon.com/general/latest/gr/apigateway.html
So... I guess, can we pivot this ticket to be a feature request to include these mappings automatically? I can create a workaround for my immediate needs, but it would be nice if Terraform could do some of the same managing of defaults for us that the console does.
Is this applicable to all situations? Im running into the situation right now where i am migrating zones and records, and trying to get the existing records up first. These are alias records that point to cloudfront instances in that account. Since I am doing cross account referencing, I dont technically have the zone id. And even if I try copy and pasting, Tf throws and error that it doesnt exist. But again to the above, I can go into console and just paste the cloudfront domain and it works
Terraform Core Version
1.4.5
AWS Provider Version
4.63.0
Affected Resource(s)
route53_record With alias defined The alias contains a name directed to an AWS apigateway domain The alias does not define a zone_id
Expected Behavior
An A alias record should be created in the hosted zone
Actual Behavior
Terraform raises a "Missing required argument" error
Relevant Error/Panic Output Snippet
Terraform Configuration Files
Steps to Reproduce
Run terraform apply with a resource configuration similar to the above
Debug Output
No response
Panic Output
No response
Important Factoids
The Terraform documentation does describe this as an invalid configuration (https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record#alias)
But the AWS documentation (https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-api-gateway.html) does not.
Further, such a configuration can be created in the AWS console, so it clearly is valid.
References
No response
Would you like to implement a fix?
None