provider/aws: Add support for delegation_set to route53_hosted_zone
This commit is contained in:
parent
bfd8226b89
commit
1411435179
|
@ -2,14 +2,15 @@ package aws
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/helper/schema"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
|
|
||||||
"github.com/awslabs/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/awslabs/aws-sdk-go/service/route53"
|
"github.com/aws/aws-sdk-go/service/route53"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAccRoute53DelegationSet_basic(t *testing.T) {
|
func TestAccRoute53DelegationSet_basic(t *testing.T) {
|
||||||
|
@ -28,6 +29,28 @@ func TestAccRoute53DelegationSet_basic(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccRoute53DelegationSet_withZones(t *testing.T) {
|
||||||
|
var zone route53.GetHostedZoneOutput
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testAccCheckRoute53ZoneDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccRoute53DelegationSetWithZonesConfig,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckRoute53DelegationSetExists("aws_route53_delegation_set.main"),
|
||||||
|
testAccCheckRoute53ZoneExists("aws_route53_zone.primary", &zone),
|
||||||
|
testAccCheckRoute53ZoneExists("aws_route53_zone.secondary", &zone),
|
||||||
|
testAccCheckRoute53NameServersMatch("aws_route53_delegation_set.main", "aws_route53_zone.primary"),
|
||||||
|
testAccCheckRoute53NameServersMatch("aws_route53_delegation_set.main", "aws_route53_zone.secondary"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testAccCheckRoute53DelegationSetDestroy(s *terraform.State, provider *schema.Provider) error {
|
func testAccCheckRoute53DelegationSetDestroy(s *terraform.State, provider *schema.Provider) error {
|
||||||
conn := provider.Meta().(*AWSClient).r53conn
|
conn := provider.Meta().(*AWSClient).r53conn
|
||||||
for _, rs := range s.RootModule().Resources {
|
for _, rs := range s.RootModule().Resources {
|
||||||
|
@ -72,8 +95,59 @@ func testAccCheckRoute53DelegationSetExists(n string) resource.TestCheckFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccCheckRoute53NameServersMatch(delegationSetName, zoneName string) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
conn := testAccProvider.Meta().(*AWSClient).r53conn
|
||||||
|
|
||||||
|
delegationSetLocal, ok := s.RootModule().Resources[delegationSetName]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", delegationSetName)
|
||||||
|
}
|
||||||
|
delegationSet, err := conn.GetReusableDelegationSet(&route53.GetReusableDelegationSetInput{
|
||||||
|
ID: aws.String(delegationSetLocal.Primary.ID),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Delegation set does not exist: %#v", delegationSetLocal.Primary.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
hostedZoneLocal, ok := s.RootModule().Resources[zoneName]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", zoneName)
|
||||||
|
}
|
||||||
|
hostedZone, err := conn.GetHostedZone(&route53.GetHostedZoneInput{
|
||||||
|
ID: aws.String(hostedZoneLocal.Primary.ID),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Delegation set does not exist: %#v", hostedZoneLocal.Primary.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(delegationSet.DelegationSet.NameServers, hostedZone.DelegationSet.NameServers) {
|
||||||
|
return fmt.Errorf("Name servers do not match:\nDelegation Set: %#v\nHosted Zone:%#v",
|
||||||
|
delegationSet.DelegationSet.NameServers, hostedZone.DelegationSet.NameServers)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const testAccRoute53DelegationSetConfig = `
|
const testAccRoute53DelegationSetConfig = `
|
||||||
resource "aws_route53_delegation_set" "test" {
|
resource "aws_route53_delegation_set" "test" {
|
||||||
reference_name = "test"
|
reference_name = "test"
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
||||||
|
const testAccRoute53DelegationSetWithZonesConfig = `
|
||||||
|
resource "aws_route53_delegation_set" "main" {
|
||||||
|
reference_name = "main"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_route53_zone" "primary" {
|
||||||
|
name = "hashicorp.com"
|
||||||
|
delegation_set_id = "${aws_route53_delegation_set.main.id}"
|
||||||
|
}
|
||||||
|
|
||||||
|
resource "aws_route53_zone" "secondary" {
|
||||||
|
name = "terraform.io"
|
||||||
|
delegation_set_id = "${aws_route53_delegation_set.main.id}"
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
|
@ -32,7 +32,7 @@ func resourceAwsRoute53Zone() *schema.Resource {
|
||||||
"comment": &schema.Schema{
|
"comment": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Default: "Managed by Terraform",
|
Default: "Managed by Terraform",
|
||||||
},
|
},
|
||||||
|
|
||||||
"vpc_id": &schema.Schema{
|
"vpc_id": &schema.Schema{
|
||||||
|
@ -53,6 +53,12 @@ func resourceAwsRoute53Zone() *schema.Resource {
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"delegation_set_id": &schema.Schema{
|
||||||
|
Type: schema.TypeString,
|
||||||
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
|
},
|
||||||
|
|
||||||
"name_servers": &schema.Schema{
|
"name_servers": &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Elem: &schema.Schema{Type: schema.TypeString},
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
|
@ -83,6 +89,10 @@ func resourceAwsRoute53ZoneCreate(d *schema.ResourceData, meta interface{}) erro
|
||||||
d.Set("vpc_region", req.VPC.VPCRegion)
|
d.Set("vpc_region", req.VPC.VPCRegion)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if v, ok := d.GetOk("delegation_set_id"); ok {
|
||||||
|
req.DelegationSetID = aws.String(v.(string))
|
||||||
|
}
|
||||||
|
|
||||||
log.Printf("[DEBUG] Creating Route53 hosted zone: %s", *req.Name)
|
log.Printf("[DEBUG] Creating Route53 hosted zone: %s", *req.Name)
|
||||||
var err error
|
var err error
|
||||||
resp, err := r53.CreateHostedZone(req)
|
resp, err := r53.CreateHostedZone(req)
|
||||||
|
@ -157,6 +167,10 @@ func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if zone.DelegationSet != nil && zone.DelegationSet.ID != nil {
|
||||||
|
d.Set("delegation_set_id", cleanDelegationSetId(*zone.DelegationSet.ID))
|
||||||
|
}
|
||||||
|
|
||||||
// get tags
|
// get tags
|
||||||
req := &route53.ListTagsForResourceInput{
|
req := &route53.ListTagsForResourceInput{
|
||||||
ResourceID: aws.String(d.Id()),
|
ResourceID: aws.String(d.Id()),
|
||||||
|
|
Loading…
Reference in New Issue