Skip to content

Commit

Permalink
Set ipv6 properties even if no ipv6 is enabled in vpc to allow usage …
Browse files Browse the repository at this point in the history
…in conditionals (fixes hashicorp#688)
  • Loading branch information
flosell authored and john-pierce committed May 21, 2018
1 parent 2a85cc7 commit 1b9713d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 5 additions & 4 deletions aws/resource_aws_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,16 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error {
// Tags
d.Set("tags", tagsToMap(vpc.Tags))

// Make sure those values are set, if an IPv6 block exists it'll be set in the loop
d.Set("assign_generated_ipv6_cidr_block", false)
d.Set("ipv6_association_id", "")
d.Set("ipv6_cidr_block", "")

for _, a := range vpc.Ipv6CidrBlockAssociationSet {
if *a.Ipv6CidrBlockState.State == "associated" { //we can only ever have 1 IPv6 block associated at once
d.Set("assign_generated_ipv6_cidr_block", true)
d.Set("ipv6_association_id", a.AssociationId)
d.Set("ipv6_cidr_block", a.Ipv6CidrBlock)
} else {
d.Set("assign_generated_ipv6_cidr_block", false)
d.Set("ipv6_association_id", "") // we blank these out to remove old entries
d.Set("ipv6_cidr_block", "")
}
}

Expand Down
3 changes: 3 additions & 0 deletions aws/resource_aws_vpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ func TestAccAWSVpc_basic(t *testing.T) {
testAccCheckVpcCidr(&vpc, "10.1.0.0/16"),
resource.TestCheckResourceAttr(
"aws_vpc.foo", "cidr_block", "10.1.0.0/16"),
// ipv6 should be empty if disabled so we can still use the property in conditionals
resource.TestCheckResourceAttr(
"aws_vpc.foo", "ipv6_cidr_block", ""),
resource.TestCheckResourceAttrSet(
"aws_vpc.foo", "default_route_table_id"),
resource.TestCheckResourceAttr(
Expand Down

0 comments on commit 1b9713d

Please sign in to comment.