From d277e1335ac328492e859f49dd81a64ef985fe6f Mon Sep 17 00:00:00 2001 From: Alex Bacchin Date: Mon, 11 Nov 2024 22:01:26 +1100 Subject: [PATCH 1/5] fixed aws_eip when ipam_pool_id is set and ReleaseAddress is called with error --- internal/service/ec2/ec2_eip.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/service/ec2/ec2_eip.go b/internal/service/ec2/ec2_eip.go index 69df5eeec91..c0c23c37151 100644 --- a/internal/service/ec2/ec2_eip.go +++ b/internal/service/ec2/ec2_eip.go @@ -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 err != nil { + return sdkdiag.AppendErrorf(diags, "deleting EC2 EIP (%s): %s", d.Id(), err) + } + + if tfawserr.ErrCodeEquals(err, errCodeInvalidAllocationIDNotFound) { + return diags + } + // 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) @@ -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 } From 9c464ba716bbf10f114531ee4c1ee838b09fbf8c Mon Sep 17 00:00:00 2001 From: Alex Bacchin Date: Mon, 11 Nov 2024 22:13:29 +1100 Subject: [PATCH 2/5] changelog updated --- .changelog/40082.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/40082.txt diff --git a/.changelog/40082.txt b/.changelog/40082.txt new file mode 100644 index 00000000000..0ae52716c81 --- /dev/null +++ b/.changelog/40082.txt @@ -0,0 +1,3 @@ +```release-note:bug +resource/aws_eip: Fix issue when deleting and EIP still in use and `ipam_pool_id` is set. +``` From 3f257058d915f1a46df2b2a039a53694d38571d4 Mon Sep 17 00:00:00 2001 From: Alex Bacchin Date: Mon, 11 Nov 2024 22:14:28 +1100 Subject: [PATCH 3/5] changelog updated --- .changelog/40082.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/40082.txt b/.changelog/40082.txt index 0ae52716c81..fc00a58f884 100644 --- a/.changelog/40082.txt +++ b/.changelog/40082.txt @@ -1,3 +1,3 @@ ```release-note:bug -resource/aws_eip: Fix issue when deleting and EIP still in use and `ipam_pool_id` is set. +resource/aws_eip: Fix issue during delete, EIP still in use and `ipam_pool_id` is set. ``` From d79b3ba7e63491fc25ef4934cc17fe307c0bfdd7 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 11 Nov 2024 11:28:32 -0500 Subject: [PATCH 4/5] r/aws_eip: ensure not found errors are handled first during delete --- internal/service/ec2/ec2_eip.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/service/ec2/ec2_eip.go b/internal/service/ec2/ec2_eip.go index c0c23c37151..4959f60ae7b 100644 --- a/internal/service/ec2/ec2_eip.go +++ b/internal/service/ec2/ec2_eip.go @@ -340,14 +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 err != nil { - return sdkdiag.AppendErrorf(diags, "deleting EC2 EIP (%s): %s", d.Id(), err) - } - 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) From ee547be71fce8c4e0d1a847e693d936b023c5785 Mon Sep 17 00:00:00 2001 From: Jared Baker Date: Mon, 11 Nov 2024 11:42:31 -0500 Subject: [PATCH 5/5] chore: tweak changelog --- .changelog/40082.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/40082.txt b/.changelog/40082.txt index fc00a58f884..dceb71dd7f0 100644 --- a/.changelog/40082.txt +++ b/.changelog/40082.txt @@ -1,3 +1,3 @@ ```release-note:bug -resource/aws_eip: Fix issue during delete, EIP still in use and `ipam_pool_id` is set. +resource/aws_eip: Properly surface errors during deletion when `ipam_pool_id` is set ```