Skip to content

Commit 9a3e677

Browse files
committed
Revert "aws_eip: 'findIPAMPoolAllocationsForEIP' is redundant."
This reverts commit 05a5e23.
1 parent 38b301e commit 9a3e677

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

internal/service/ec2/ec2_eip.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ import (
1616
awstypes "github.com/aws/aws-sdk-go-v2/service/ec2/types"
1717
"github.com/hashicorp/aws-sdk-go-base/v2/tfawserr"
1818
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
19+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
1920
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
2021
"github.com/hashicorp/terraform-provider-aws/internal/conns"
2122
"github.com/hashicorp/terraform-provider-aws/internal/enum"
2223
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
24+
tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices"
2325
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
2426
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
2527
"github.com/hashicorp/terraform-provider-aws/names"
@@ -337,7 +339,7 @@ func resourceEIPDelete(ctx context.Context, d *schema.ResourceData, meta any) di
337339
timeout = 10 * time.Minute // IPAM eventual consistency
338340
)
339341
_, 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))
341343
})
342344

343345
if err != nil {
@@ -428,3 +430,25 @@ func disassociateEIP(ctx context.Context, conn *ec2.Client, associationID string
428430
func eipARN(ctx context.Context, c *conns.AWSClient, allocationID string) string {
429431
return c.RegionalARN(ctx, names.EC2, "elastic-ip/"+allocationID)
430432
}
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

Comments
 (0)