Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i specify the dns servers when terrafrorm uses aws_route53_zone

When terraform runs the following, it apparently picks random NS servers:

resource "aws_route53_zone" "example.com" {
  name = "example.com"
}

The problem with this is that the registered domain that I have in AWS already has specified NS servers. Is there a way to specify the NS servers this resource uses - or maybe change the hosted domain's NS servers to what is picked when the zone is created?

like image 778
TyMac Avatar asked Oct 30 '22 06:10

TyMac


2 Answers

When you create a new zone, AWS generates the Name server list for you. Using this example from Terraform.

resource "aws_route53_zone" "dev" {
  name = "dev.example.com"

  tags {
    Environment = "dev"
  }
}

resource "aws_route53_record" "dev-ns" {
  zone_id = "${aws_route53_zone.main.zone_id}"
  name    = "dev.example.com"
  type    = "NS"
  ttl     = "30"

  records = [
    "${aws_route53_zone.dev.name_servers.0}",
    "${aws_route53_zone.dev.name_servers.1}",
    "${aws_route53_zone.dev.name_servers.2}",
    "${aws_route53_zone.dev.name_servers.3}",
  ]
}

https://www.terraform.io/docs/providers/aws/r/route53_zone.html

API returns a Delegation Set after the call to Create Zone.

http://docs.aws.amazon.com/Route53/latest/APIReference/API_CreateHostedZone.html#API_CreateHostedZone_ResponseSyntax

like image 113
strongjz Avatar answered Nov 15 '22 06:11

strongjz


I have been able to specify DNS servers but I would imagine that AWS is allocating servers based on availability, load etc... so you may want to think hard about baking these configs in.

resource "aws_route53_record" "primary-ns" {
  zone_id = "${aws_route53_zone.primary.zone_id}"
  name    = "www.bacon.rocks"
  type = "NS"
  ttl = "172800"
  records = ["ns-869.awsdns-44.net","ns-1237.awsdns-26.org","ns-1846.awsdns-38.co.uk","ns-325.awsdns-40.com"]
}

or something along those lines

like image 35
nick fox Avatar answered Nov 15 '22 05:11

nick fox