如何在Terraform中配置Route53的CNAME Alias记录?目标配置位置存疑
Hey there, let's clear up the confusion here! First, a key point to understand: Route53 Alias records only work with AWS-managed resources (like ELBs, CloudFront distributions, S3 static websites, or other records within the same Route53 hosted zone). Since your target is an external domain (server.some-external-domain.de), you can't use an Alias record here—you'll need to create a standard CNAME record instead, matching your existing DNS entry.
Here's the Terraform code for your specific record:
resource "aws_route53_record" "something_cname" { zone_id = "${aws_route53_zone.your_zone.zone_id}" # Replace with your Route53 zone ID reference name = "something.domainmanagedbyroute53.de" type = "CNAME" ttl = 3600 records = ["server.some-external-domain."] # Note the trailing dot to avoid zone suffix addition }
A quick breakdown of the code:
zone_id: Replace this with the reference to your Route53 hosted zone (either using a resource reference like${aws_route53_zone.your_zone.zone_id}or hardcode the zone ID if you prefer)name: Exact subdomain from your original recordtype: Set toCNAMEsince we're pointing to an external domainttl: Matches your original 3600 valuerecords: The target external domain, with a trailing dot to ensure Route53 doesn't append your hosted zone's domain suffix automatically
To clarify why the Alias example from the docs doesn't apply here: that example uses an Alias to point to an AWS ELB, which is an AWS-managed resource. Alias records have benefits like automatic health checks (when applicable) and no TTL limitations, but they're restricted to AWS-owned targets. For external domains, stick with the standard CNAME record as shown above.
内容的提问来源于stack exchange,提问作者user2656732




