I want to transfer my DNS zone from AWS Route53 to Cloudflare.
The domain has been registered on AWS and will stay there, however, all the DNS configuration (zone, fields... etc...) is moving into Cloudflare.
All my infrastructure is handled through Terraform, and so far, all the DNS configuration has been moved to Cloudflare by adding DNS records into Terraform (cloudflare_zone, cloudflare_record... etc...).
In order to make the final switch to Cloudflare, I have to change the name servers associated with my domain registered in AWS. I have to change them from the AWS name servers by the Cloudflare name servers.
However, I cannot find any Terraform-way to change the name servers associated to my domain.
I have tried adding the Cloudflare name servers directly as NS servers of the AWS zone, but nothing happens when doing so:
resource "aws_route53_record" "nameservers" {
type = "NS"
records = ["...expected cloudflare nameserver..."]
...
}
}
I have followed the official Cloudflare migration documentation (https://developers.cloudflare.com/dns/zone-setups/full-setup/setup/#update-your-registrar) and the AWS specifications: https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/domain-name-servers-glue-records.html#domain-name-servers-glue-records-adding-changing.
In AWS, name servers for a domain can be updated directly through the console in "Route53" > "Registered domains" > "Details" > "Edit name servers".
Is there any way to edit those domain name servers through Terraform ?

It appears that there is a resource:
required provider version: >= 4.4.0
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53domains_registered_domain
terraform will just import it into state to manage it (seems like you dont need to manually import it , terraform will know how to handle this)
then you would update the
name_serverblock in the resource to the cloud flare nameservershope that this helps
note: before you do the migration reduce the ttls to 600 seconds(10 mins) on any records and on the zone in route 53 for the migration and wait for the ttls to lapse