verify VPC association on private zone
This commit is contained in:
parent
a51bc6007d
commit
8e62a14f29
|
@ -119,7 +119,7 @@ func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if zone.DelegationSet != nil {
|
if ! *zone.HostedZone.Config.PrivateZone {
|
||||||
ns := make([]string, len(zone.DelegationSet.NameServers))
|
ns := make([]string, len(zone.DelegationSet.NameServers))
|
||||||
for i := range zone.DelegationSet.NameServers {
|
for i := range zone.DelegationSet.NameServers {
|
||||||
ns[i] = *zone.DelegationSet.NameServers[i]
|
ns[i] = *zone.DelegationSet.NameServers[i]
|
||||||
|
@ -130,6 +130,7 @@ func resourceAwsRoute53ZoneRead(d *schema.ResourceData, meta interface{}) error
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
d.Set("name_servers", nil);
|
d.Set("name_servers", nil);
|
||||||
|
//TODO Verify that the configure VPC is still associated
|
||||||
}
|
}
|
||||||
|
|
||||||
// get tags
|
// get tags
|
||||||
|
|
|
@ -64,7 +64,7 @@ func TestCleanChangeID(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccRoute53Zone(t *testing.T) {
|
func TestAccRoute53Zone(t *testing.T) {
|
||||||
var zone route53.HostedZone
|
var zone route53.GetHostedZoneOutput
|
||||||
var td route53.ResourceTagSet
|
var td route53.ResourceTagSet
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
|
@ -85,7 +85,7 @@ func TestAccRoute53Zone(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAccRoute53PrivateZone(t *testing.T) {
|
func TestAccRoute53PrivateZone(t *testing.T) {
|
||||||
var zone route53.HostedZone
|
var zone route53.GetHostedZoneOutput
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
@ -96,6 +96,7 @@ func TestAccRoute53PrivateZone(t *testing.T) {
|
||||||
Config: testAccRoute53PrivateZoneConfig,
|
Config: testAccRoute53PrivateZoneConfig,
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckRoute53ZoneExists("aws_route53_zone.main", &zone),
|
testAccCheckRoute53ZoneExists("aws_route53_zone.main", &zone),
|
||||||
|
testAccCheckRoute53ZoneAssociationExists("aws_vpc.main", &zone),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -117,7 +118,7 @@ func testAccCheckRoute53ZoneDestroy(s *terraform.State) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccCheckRoute53ZoneExists(n string, zone *route53.HostedZone) resource.TestCheckFunc {
|
func testAccCheckRoute53ZoneExists(n string, zone *route53.GetHostedZoneOutput) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
rs, ok := s.RootModule().Resources[n]
|
rs, ok := s.RootModule().Resources[n]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -134,7 +135,7 @@ func testAccCheckRoute53ZoneExists(n string, zone *route53.HostedZone) resource.
|
||||||
return fmt.Errorf("Hosted zone err: %v", err)
|
return fmt.Errorf("Hosted zone err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.DelegationSet != nil {
|
if ! *resp.HostedZone.Config.PrivateZone {
|
||||||
sorted_ns := make([]string, len(resp.DelegationSet.NameServers))
|
sorted_ns := make([]string, len(resp.DelegationSet.NameServers))
|
||||||
for i, ns := range resp.DelegationSet.NameServers {
|
for i, ns := range resp.DelegationSet.NameServers {
|
||||||
sorted_ns[i] = *ns
|
sorted_ns[i] = *ns
|
||||||
|
@ -149,16 +150,40 @@ func testAccCheckRoute53ZoneExists(n string, zone *route53.HostedZone) resource.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*zone = *resp.HostedZone
|
*zone = *resp
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAccLoadTagsR53(zone *route53.HostedZone, td *route53.ResourceTagSet) resource.TestCheckFunc {
|
func testAccCheckRoute53ZoneAssociationExists(n string, zone *route53.GetHostedZoneOutput) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
rs, ok := s.RootModule().Resources[n]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Not found: %s", n)
|
||||||
|
}
|
||||||
|
|
||||||
|
if rs.Primary.ID == "" {
|
||||||
|
return fmt.Errorf("No VPC ID is set")
|
||||||
|
}
|
||||||
|
|
||||||
|
var associatedVPC *route53.VPC
|
||||||
|
for _, vpc := range zone.VPCs {
|
||||||
|
if *vpc.VPCID == rs.Primary.ID {
|
||||||
|
associatedVPC = vpc
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if associatedVPC == nil {
|
||||||
|
return fmt.Errorf("VPC: %v is not associated to Zone: %v")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func testAccLoadTagsR53(zone *route53.GetHostedZoneOutput, td *route53.ResourceTagSet) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
conn := testAccProvider.Meta().(*AWSClient).r53conn
|
conn := testAccProvider.Meta().(*AWSClient).r53conn
|
||||||
|
|
||||||
zone := cleanZoneID(*zone.ID)
|
zone := cleanZoneID(*zone.HostedZone.ID)
|
||||||
req := &route53.ListTagsForResourceInput{
|
req := &route53.ListTagsForResourceInput{
|
||||||
ResourceID: aws.String(zone),
|
ResourceID: aws.String(zone),
|
||||||
ResourceType: aws.String("hostedzone"),
|
ResourceType: aws.String("hostedzone"),
|
||||||
|
|
Loading…
Reference in New Issue