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:
Mitchell Hashimoto 2015-04-22 12:10:27 +02:00
commit 8ca42f832e
3 changed files with 36 additions and 3 deletions

View File

@ -1,10 +1,12 @@
package aws package aws
import ( import (
"fmt"
"log" "log"
"strings" "strings"
"time" "time"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
@ -31,6 +33,15 @@ func resourceAwsRoute53Zone() *schema.Resource {
Computed: true, 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(), "tags": tagsSchema(),
}, },
} }
@ -80,7 +91,7 @@ func resourceAwsRoute53ZoneCreate(d *schema.ResourceData, meta interface{}) erro
func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error { func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error {
r53 := meta.(*AWSClient).r53conn 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 { if err != nil {
// Handle a deleted zone // Handle a deleted zone
if r53err, ok := err.(aws.APIError); ok && r53err.Code == "NoSuchHostedZone" { if r53err, ok := err.(aws.APIError); ok && r53err.Code == "NoSuchHostedZone" {
@ -90,6 +101,14 @@ func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error
return err 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 // get tags
req := &route53.ListTagsForResourceInput{ req := &route53.ListTagsForResourceInput{
ResourceID: aws.String(d.Id()), ResourceID: aws.String(d.Id()),

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -114,6 +115,15 @@ func testAccCheckRoute53ZoneExists(n string, zone *route53.HostedZone) resource.
if err != nil { if err != nil {
return fmt.Errorf("Hosted zone err: %v", err) 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 *zone = *resp.HostedZone
return nil return nil
} }

View File

@ -29,7 +29,6 @@ resource "aws_route53_zone" "main" {
resource "aws_route53_zone" "dev" { resource "aws_route53_zone" "dev" {
name = "dev.example.com" name = "dev.example.com"
parent_route53_zone = "${aws_route53_zone.main.zone_id}"
} }
resource "aws_route53_record" "dev-ns" { resource "aws_route53_record" "dev-ns" {
@ -37,7 +36,12 @@ resource "aws_route53_record" "dev-ns" {
name = "dev.example.com" name = "dev.example.com"
type = "NS" type = "NS"
ttl = "30" 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}"
]
} }
``` ```