From bd6ff34aa2934cb13a7bf93d2ce72ce9e44b5684 Mon Sep 17 00:00:00 2001 From: John Engelman Date: Mon, 11 May 2015 10:20:34 -0500 Subject: [PATCH] Retrieve nameservers for private hosted zone. --- .../aws/resource_aws_route53_zone.go | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_route53_zone.go b/builtin/providers/aws/resource_aws_route53_zone.go index d3c8a21cf..b89907371 100644 --- a/builtin/providers/aws/resource_aws_route53_zone.go +++ b/builtin/providers/aws/resource_aws_route53_zone.go @@ -131,7 +131,14 @@ func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("[DEBUG] Error setting name servers for: %s, error: %#v", d.Id(), err) } } else { - d.Set("name_servers", nil) + ns, err := getNameServers(d.Id(), d.Get("name").(string), r53) + if err != nil { + return err + } + if err := d.Set("name_servers", ns); err != nil { + return fmt.Errorf("[DEBUG] Error setting name servers for: %s, error: %#v", d.Id(), err) + } + var associatedVPC *route53.VPC for _, vpc := range zone.VPCs { if *vpc.VPCID == d.Get("vpc_id") { @@ -217,3 +224,23 @@ func cleanPrefix(ID, prefix string) string { } return ID } + +func getNameServers(zoneId string, zoneName string, r53 *route53.Route53) ([]string, error) { + resp, err := r53.ListResourceRecordSets(&route53.ListResourceRecordSetsInput{ + HostedZoneID: aws.String(zoneId), + StartRecordName: aws.String(zoneName), + StartRecordType: aws.String("NS"), + }) + if err != nil { + return nil, err + } + if len(resp.ResourceRecordSets) == 0 { + return nil, nil + } + ns := make([]string, len(resp.ResourceRecordSets[0].ResourceRecords)) + for i := range resp.ResourceRecordSets[0].ResourceRecords { + ns[i] = *resp.ResourceRecordSets[0].ResourceRecords[i].Value + } + sort.Strings(ns) + return ns, nil +}