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

Expose Route53 zone nameservers for parent zone NS record #1525

Merged
merged 7 commits into from
Apr 22, 2015
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion builtin/providers/aws/resource_aws_route53_zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ func resourceAwsRoute53Zone() *schema.Resource {
Computed: true,
},

"delegation_set_name_servers": &schema.Schema{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would just nameservers be a bad choice here? Not required for changing, just curious on your thoughts 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally had it as nameservers, but decided it might be better just to be clear where it's actually coming from in the AWS API.

Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Computed: true,
},

"tags": tagsSchema(),
},
}
Expand Down Expand Up @@ -80,7 +86,7 @@ func resourceAwsRoute53ZoneCreate(d *schema.ResourceData, meta interface{}) erro

func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error {
r53 := meta.(*AWSClient).r53conn
_, err := r53.GetHostedZone(&route53.GetHostedZoneRequest{ID: aws.String(d.Id())})
zone, err := r53.GetHostedZone(&route53.GetHostedZoneRequest{ID: aws.String(d.Id())})
if err != nil {
// Handle a deleted zone
if r53err, ok := err.(aws.APIError); ok && r53err.Code == "NoSuchHostedZone" {
Expand All @@ -90,6 +96,8 @@ func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error
return err
}

d.Set("delegation_set_name_servers", zone.DelegationSet.NameServers)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d.Set can return an error, can you check to make sure it's nil? We've seen bugs go by silently by not checking for errors when setting a non-primitive type.

if err := d.Set("delegation_set_name_servers", zone.DelegationSet.NameServers); err != nil{

or similar, like in https://github.com/hashicorp/terraform/blob/master/builtin/providers/aws/resource_aws_route53_record.go#L199


// get tags
req := &route53.ListTagsForResourceRequest{
ResourceID: aws.String(d.Id()),
Expand Down
9 changes: 9 additions & 0 deletions builtin/providers/aws/resource_aws_route53_zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ func testAccCheckRoute53ZoneExists(n string, zone *route53.HostedZone) resource.
if err != nil {
return fmt.Errorf("Hosted zone err: %v", err)
}

for i, ns := range resp.DelegationSet.NameServers {
attribute := fmt.Sprintf("delegation_set_name_servers.%d", i)
dsns := rs.Primary.Attributes[attribute]
if dsns != ns {
return fmt.Errorf("Got: %v for %v, Expected: %v", dsns, attribute, ns)
}
}

*zone = *resp.HostedZone
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,19 @@ resource "aws_route53_zone" "main" {

resource "aws_route53_zone" "dev" {
name = "dev.example.com"
parent_route53_zone = "${aws_route53_zone.main.zone_id}"
}

resource "aws_route53_record" "dev-ns" {
zone_id = "${aws_route53_zone.main.zone_id}"
name = "dev.example.com"
type = "NS"
ttl = "30"
records = ["127.0.0.1", "127.0.0.27"]
records = [
"${aws_route53_zone.dev.delegation_set_name_servers.0}",
"${aws_route53_zone.dev.delegation_set_name_servers.1}",
"${aws_route53_zone.dev.delegation_set_name_servers.2}",
"${aws_route53_zone.dev.delegation_set_name_servers.3}"
]
}
```

Expand Down