@@ -16,10 +16,12 @@ import (
16
16
awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types"
17
17
"github.com/hashicorp/aws-sdk-go-base/v2/tfawserr"
18
18
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
19
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
19
20
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
20
21
"github.com/hashicorp/terraform-provider-aws/internal/conns"
21
22
"github.com/hashicorp/terraform-provider-aws/internal/enum"
22
23
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
24
+ tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices"
23
25
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
24
26
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
25
27
"github.com/hashicorp/terraform-provider-aws/names"
@@ -337,7 +339,7 @@ func resourceEIPDelete(ctx context.Context, d *schema.ResourceData, meta any) di
337
339
timeout = 10 * time .Minute // IPAM eventual consistency
338
340
)
339
341
_ , err := tfresource .RetryUntilNotFound (ctx , timeout , func (ctx context.Context ) (any , error ) {
340
- return findIPAMPoolAllocationsByIPAMPoolIDAndResourceID (ctx , conn , ipamPoolID , d .Get ("allocation_id" ).(string ))
342
+ return findIPAMPoolAllocationsForEIP (ctx , conn , ipamPoolID , d .Get ("allocation_id" ).(string ))
341
343
})
342
344
343
345
if err != nil {
@@ -428,3 +430,25 @@ func disassociateEIP(ctx context.Context, conn *ec2.Client, associationID string
428
430
func eipARN (ctx context.Context , c * conns.AWSClient , allocationID string ) string {
429
431
return c .RegionalARN (ctx , names .EC2 , "elastic-ip/" + allocationID )
430
432
}
433
+
434
+ func findIPAMPoolAllocationsForEIP (ctx context.Context , conn * ec2.Client , ipamPoolID , eipAllocationID string ) ([]awstypes.IpamPoolAllocation , error ) {
435
+ input := ec2.GetIpamPoolAllocationsInput {
436
+ IpamPoolId : aws .String (ipamPoolID ),
437
+ }
438
+
439
+ output , err := findIPAMPoolAllocations (ctx , conn , & input )
440
+
441
+ if err != nil {
442
+ return nil , err
443
+ }
444
+
445
+ output = tfslices .Filter (output , func (v awstypes.IpamPoolAllocation ) bool {
446
+ return v .ResourceType == awstypes .IpamPoolAllocationResourceTypeEip && aws .ToString (v .ResourceId ) == eipAllocationID
447
+ })
448
+
449
+ if len (output ) == 0 {
450
+ return nil , & retry.NotFoundError {}
451
+ }
452
+
453
+ return output , nil
454
+ }
0 commit comments