Skip to content

Commit

Permalink
Merge pull request hashicorp#40082 from alexbacchin/b/aws_eip-release…
Browse files Browse the repository at this point in the history
…_error

b/aws_eip on delete error with ipam_pool_id stuck in IPAM eventual consistency loop
  • Loading branch information
jar-b authored Nov 11, 2024
2 parents dded6da + ee547be commit d82ef74
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
3 changes: 3 additions & 0 deletions .changelog/40082.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_eip: Properly surface errors during deletion when `ipam_pool_id` is set
```
16 changes: 8 additions & 8 deletions internal/service/ec2/ec2_eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,14 @@ func resourceEIPDelete(ctx context.Context, d *schema.ResourceData, meta interfa
log.Printf("[INFO] Deleting EC2 EIP: %s", d.Id())
_, err := conn.ReleaseAddress(ctx, input)

if tfawserr.ErrCodeEquals(err, errCodeInvalidAllocationIDNotFound) {
return diags
}

if err != nil {
return sdkdiag.AppendErrorf(diags, "deleting EC2 EIP (%s): %s", d.Id(), err)
}

// If the EIP's CIDR block was allocated from an IPAM pool, wait for the allocation to disappear.
if v, ok := d.GetOk("ipam_pool_id"); ok {
ipamPoolID := v.(string)
Expand All @@ -355,14 +363,6 @@ func resourceEIPDelete(ctx context.Context, d *schema.ResourceData, meta interfa
}
}

if tfawserr.ErrCodeEquals(err, errCodeInvalidAllocationIDNotFound) {
return diags
}

if err != nil {
return sdkdiag.AppendErrorf(diags, "deleting EC2 EIP (%s): %s", d.Id(), err)
}

return diags
}

Expand Down

0 comments on commit d82ef74

Please sign in to comment.