Skip to content

Commit

Permalink
Set ipv6 properties even if no ipv6 is enabled in subnet to allow us…
Browse files Browse the repository at this point in the history
…age in conditionals (fixes terraform-providers#688 but for subnet instead of VPC)
  • Loading branch information
pdecat committed Nov 22, 2018
1 parent e8bb27f commit d98e824
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions aws/resource_aws_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,16 @@ func resourceAwsSubnetRead(d *schema.ResourceData, meta interface{}) error {
d.Set("cidr_block", subnet.CidrBlock)
d.Set("map_public_ip_on_launch", subnet.MapPublicIpOnLaunch)
d.Set("assign_ipv6_address_on_creation", subnet.AssignIpv6AddressOnCreation)

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

for _, a := range subnet.Ipv6CidrBlockAssociationSet {
if *a.Ipv6CidrBlockState.State == "associated" { //we can only ever have 1 IPv6 block associated at once
d.Set("ipv6_cidr_block_association_id", a.AssociationId)
d.Set("ipv6_cidr_block", a.Ipv6CidrBlock)
break
} else {
d.Set("ipv6_cidr_block_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_subnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ func TestAccAWSSubnet_basic(t *testing.T) {
testAccCheckSubnetExists(
"aws_subnet.foo", &v),
testCheck,
// ipv6 should be empty if disabled so we can still use the property in conditionals
resource.TestCheckResourceAttr(
"aws_subnet.foo", "ipv6_cidr_block", ""),
resource.TestMatchResourceAttr(
"aws_subnet.foo",
"arn",
Expand Down

0 comments on commit d98e824

Please sign in to comment.