Merge pull request #1525 from Banno/route53-zone-nameservers
providers/aws: Expose Route53 zone nameservers for parent zone NS record
This commit is contained in:
commit
8ca42f832e
|
@ -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()),
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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}"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in New Issue