Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws_route53_zone should not sort its name_servers list #21965

Closed
wilkej opened this issue Nov 30, 2021 · 4 comments · Fixed by #27293
Closed

aws_route53_zone should not sort its name_servers list #21965

wilkej opened this issue Nov 30, 2021 · 4 comments · Fixed by #27293
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/route53 Issues and PRs that pertain to the route53 service.

Comments

@wilkej
Copy link

wilkej commented Nov 30, 2021

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform CLI and Terraform AWS Provider Version

Terraform v1.0.11
on linux_amd64
+ provider registry.terraform.io/hashicorp/aws v3.64.2
+ provider registry.terraform.io/hashicorp/template v2.2.0

Affected Resource(s)

  • aws_route53_zone

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

resource "aws_route53_zone" "route53zone" {
  name     = "my-domain.com"
}

resource "aws_route53_record" "record" {
  name    = "my-domain.com"
  ttl     = 900
  type    = "SOA"
  zone_id = aws_route53_zone.route53zone.zone_id
  records = [
    "${aws_route53_zone.route53zone.name_servers[3]}. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400"
  ]
}

Expected Behavior

This issue is basically a copy of #3447

I'd like to manage the Route 53 SOA record in Terraform, in order to control the negative caching TTL.

The following record would seem to work, except that name_servers[0] is not the primary name server that AWS chooses by default, because the order of name_servers is not preserved by Terraform.

It appears that Terraform sorts the list. Is there a good reason for this? I wouldn't expect AWS to start reordering these arbitrarily.

Actual Behavior

Nameserver output is sorted

References

aws route53 get-hosted-zone --id ... output is different than

output "r53_record_test_for_me" {
  value = aws_route53_zone.route53zone.name_servers
}
@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. service/route53 Issues and PRs that pertain to the route53 service. labels Nov 30, 2021
@justinretzolk justinretzolk added enhancement Requests to existing resources that expand the functionality or scope. and removed needs-triage Waiting for first response or review from a maintainer. labels Dec 7, 2021
@jbg
Copy link
Contributor

jbg commented Feb 24, 2022

I hit this today, also when trying to set up SOA records programmatically.

The sorting is unfortunate, but removing it might cause a lot of unwanted changes in existing configs. Maybe a primary_name_server attribute could be added to provide what should be name_servers[0] if they were not sorted?

@sjparkinson
Copy link
Contributor

Looks like there isn't any sorting happening for the aws_route53_zone data source if anyone is looking for a workaround.

Not ideal as it's another Route 53 API call. And curious that there is different logic across the data source and the resource.

@sjparkinson
Copy link
Contributor

I can confirm the follow is a workaround if you're looking to set the SOA record for example:

# This works around the sorting applied to the list of name server by the AWS
# Terraform provider in the `aws_route53_zone` resource. No sorting is applied
# to the list in the data source.
data "aws_route53_zone" "zone" {
  name = "${aws_route53_zone.zone.name}."
}

resource "aws_route53_record" "soa" {
  zone_id = aws_route53_zone.zone.zone_id
  name    = aws_route53_zone.zone.name
  type    = "SOA"
  ttl     = 900

  # See https://www.cloudflare.com/en-gb/learning/dns/dns-records/dns-soa-record/ for more information about SOA records.
  records = [
    "${data.aws_route53_zone.zone.name_servers[0]}. username.exampe.com. 1 7200 900 1209600 60",
  ]
}

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/route53 Issues and PRs that pertain to the route53 service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants