diff --git a/builtin/providers/aws/resource_aws_route53_zone.go b/builtin/providers/aws/resource_aws_route53_zone.go index 44f3a92c8..5c55fb3e1 100644 --- a/builtin/providers/aws/resource_aws_route53_zone.go +++ b/builtin/providers/aws/resource_aws_route53_zone.go @@ -1,10 +1,12 @@ package aws import ( + "fmt" "log" "strings" "time" + "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" @@ -31,6 +33,15 @@ func resourceAwsRoute53Zone() *schema.Resource { Computed: true, }, + "name_servers": &schema.Schema{ + Type: schema.TypeSet, + Elem: &schema.Schema{Type: schema.TypeString}, + Computed: true, + Set: func(v interface{}) int { + return hashcode.String(v.(string)) + }, + }, + "tags": tagsSchema(), }, } @@ -80,7 +91,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.GetHostedZoneInput{ID: aws.String(d.Id())}) + zone, err := r53.GetHostedZone(&route53.GetHostedZoneInput{ID: aws.String(d.Id())}) if err != nil { // Handle a deleted zone if r53err, ok := err.(aws.APIError); ok && r53err.Code == "NoSuchHostedZone" { @@ -90,6 +101,14 @@ func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error return err } + ns := make([]string, len(zone.DelegationSet.NameServers)) + for i := range zone.DelegationSet.NameServers { + ns[i] = *zone.DelegationSet.NameServers[i] + } + if err := d.Set("name_servers", ns); err != nil { + return fmt.Errorf("[DEBUG] Error setting name servers for: %s, error: %#v", d.Id(), err) + } + // get tags req := &route53.ListTagsForResourceInput{ ResourceID: aws.String(d.Id()), diff --git a/builtin/providers/aws/resource_aws_route53_zone_test.go b/builtin/providers/aws/resource_aws_route53_zone_test.go index eedad0ac1..4686831e0 100644 --- a/builtin/providers/aws/resource_aws_route53_zone_test.go +++ b/builtin/providers/aws/resource_aws_route53_zone_test.go @@ -4,6 +4,7 @@ import ( "fmt" "testing" + "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" @@ -114,6 +115,15 @@ func testAccCheckRoute53ZoneExists(n string, zone *route53.HostedZone) resource. if err != nil { return fmt.Errorf("Hosted zone err: %v", err) } + + for _, ns := range resp.DelegationSet.NameServers { + attribute := fmt.Sprintf("name_servers.%d", hashcode.String(*ns)) + 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 } diff --git a/website/source/docs/providers/aws/r/route53_zone.html.markdown b/website/source/docs/providers/aws/r/route53_zone.html.markdown index 7b0cf9388..67a5f79f1 100644 --- a/website/source/docs/providers/aws/r/route53_zone.html.markdown +++ b/website/source/docs/providers/aws/r/route53_zone.html.markdown @@ -29,7 +29,6 @@ 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" { @@ -37,7 +36,12 @@ resource "aws_route53_record" "dev-ns" { 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}" + ] } ```