Search code examples
terraformterraform-provider-awsamazon-route53

Is it possible for Route 53 nameservers to survive terraform destroy so that they work when reapplied?


I want to use Terraform to temporarily spin up a site on AWS from time to time (no need to pay for resources when they're not being used). I'd like Terraform to manage the DNS.

The domain is not hosted in Route 53, therefore the nameservers need to be manually configured. After terraform destroy, everything is removed (including the Route 53 zones which list the nameservers).

The next time everything is brought back up with terraform apply, I want the same Route 53 nameservers so that they don't need to be manually configured each time. Is there a recommended way to achieve this?

I've seen this question, which is similar, but wanted to avoid prescribing an approach and describe the problem instead.


Solution

  • Create a Route53 delegation set outside of terraform; this is a re-usable set of four nameservers that can be used by multiple zones without the usual randomly rotating set of selections.

    Once you've done so, you can provide its ID as a string when provisioning Terraform Route53 resources...

    resource "aws_route53_zone" "primary" {
      name              = "example.com"
      delegation_set_id = "SET-ID"
    }