Skip to content

Commit

Permalink
Merge pull request #24685 from moses-aronov/b-aws_subnet-fix
Browse files Browse the repository at this point in the history
Fixes aws_subnet on creation improperly handling IPv6 CIDR pending association state
  • Loading branch information
ewbankkit authored May 6, 2022
2 parents 07ec376 + 70e2b07 commit 0384cb0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .changelog/24685.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:bug
resource/aws_subnet: Fix `InvalidSubnet.Conflict` errors when associating IPv6 CIDR blocks
```

```release-note:bug
resource/aws_default_subnet: Fix `InvalidSubnet.Conflict` errors when associating IPv6 CIDR blocks
```
6 changes: 4 additions & 2 deletions internal/service/ec2/vpc_default_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,17 @@ func resourceDefaultSubnetCreate(d *schema.ResourceData, meta interface{}) error
}

// Creating an IPv6-native default subnets associates an IPv6 CIDR block.
for _, v := range subnet.Ipv6CidrBlockAssociationSet {
for i, v := range subnet.Ipv6CidrBlockAssociationSet {
if aws.StringValue(v.Ipv6CidrBlockState.State) == ec2.SubnetCidrBlockStateCodeAssociating { //we can only ever have 1 IPv6 block associated at once
associationID := aws.StringValue(v.AssociationId)

_, err = WaitSubnetIPv6CIDRBlockAssociationCreated(conn, associationID)
subnetCidrBlockState, err := WaitSubnetIPv6CIDRBlockAssociationCreated(conn, associationID)

if err != nil {
return fmt.Errorf("error waiting for EC2 Default Subnet (%s) IPv6 CIDR block (%s) to become associated: %w", d.Id(), associationID, err)
}

subnet.Ipv6CidrBlockAssociationSet[i].Ipv6CidrBlockState = subnetCidrBlockState
}
}

Expand Down
6 changes: 4 additions & 2 deletions internal/service/ec2/vpc_subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,17 @@ func resourceSubnetCreate(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("error waiting for EC2 Subnet (%s) create: %w", d.Id(), err)
}

for _, v := range subnet.Ipv6CidrBlockAssociationSet {
for i, v := range subnet.Ipv6CidrBlockAssociationSet {
if aws.StringValue(v.Ipv6CidrBlockState.State) == ec2.SubnetCidrBlockStateCodeAssociating { //we can only ever have 1 IPv6 block associated at once
associationID := aws.StringValue(v.AssociationId)

_, err = WaitSubnetIPv6CIDRBlockAssociationCreated(conn, associationID)
subnetCidrBlockState, err := WaitSubnetIPv6CIDRBlockAssociationCreated(conn, associationID)

if err != nil {
return fmt.Errorf("error waiting for EC2 Subnet (%s) IPv6 CIDR block (%s) to become associated: %w", d.Id(), associationID, err)
}

subnet.Ipv6CidrBlockAssociationSet[i].Ipv6CidrBlockState = subnetCidrBlockState
}
}

Expand Down

0 comments on commit 0384cb0

Please sign in to comment.