Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes aws_subnet on creation improperly handling IPv6 CIDR pending association state #24685

Merged
merged 5 commits into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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