Retrieve nameservers for private hosted zone.

This commit is contained in:
John Engelman 2015-05-11 10:20:34 -05:00
parent a6fdb04829
commit bd6ff34aa2
1 changed files with 28 additions and 1 deletions

View File

@ -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) return fmt.Errorf("[DEBUG] Error setting name servers for: %s, error: %#v", d.Id(), err)
} }
} else { } 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 var associatedVPC *route53.VPC
for _, vpc := range zone.VPCs { for _, vpc := range zone.VPCs {
if *vpc.VPCID == d.Get("vpc_id") { if *vpc.VPCID == d.Get("vpc_id") {
@ -217,3 +224,23 @@ func cleanPrefix(ID, prefix string) string {
} }
return ID 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
}