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

r/aws_eip: use retry logic when creating new resources #32016

Merged
merged 4 commits into from
Jun 16, 2023
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
3 changes: 3 additions & 0 deletions .changelog/32016.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_eip: Fix `reading EC2 EIP (eipalloc-abcd1234): couldn't find resource` errors when reading new resource
```
9 changes: 5 additions & 4 deletions internal/service/ec2/ec2_eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ func resourceEIPRead(ctx context.Context, d *schema.ResourceData, meta interface
return sdkdiag.AppendErrorf(diags, `with the retirement of EC2-Classic %s domain EC2 EIPs are no longer supported`, ec2.DomainTypeStandard)
}

address, err := FindEIPByAllocationID(ctx, conn, d.Id())
outputRaw, err := tfresource.RetryWhenNewResourceNotFound(ctx, propagationTimeout, func() (interface{}, error) {
return FindEIPByAllocationID(ctx, conn, d.Id())
}, d.IsNewResource())

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] EC2 EIP (%s) not found, removing from state", d.Id())
Expand All @@ -214,6 +216,7 @@ func resourceEIPRead(ctx context.Context, d *schema.ResourceData, meta interface
return sdkdiag.AppendErrorf(diags, "reading EC2 EIP (%s): %s", d.Id(), err)
}

address := outputRaw.(*ec2.Address)
d.Set("allocation_id", address.AllocationId)
d.Set("association_id", address.AssociationId)
d.Set("carrier_ip", address.CarrierIp)
Expand All @@ -224,17 +227,15 @@ func resourceEIPRead(ctx context.Context, d *schema.ResourceData, meta interface
d.Set("network_border_group", address.NetworkBorderGroup)
d.Set("network_interface", address.NetworkInterfaceId)
d.Set("public_ipv4_pool", address.PublicIpv4Pool)
d.Set("vpc", aws.StringValue(address.Domain) == ec2.DomainTypeVpc)

d.Set("private_ip", address.PrivateIpAddress)
if v := aws.StringValue(address.PrivateIpAddress); v != "" {
d.Set("private_dns", PrivateDNSNameForIP(meta.(*conns.AWSClient), v))
}

d.Set("public_ip", address.PublicIp)
if v := aws.StringValue(address.PublicIp); v != "" {
d.Set("public_dns", PublicDNSNameForIP(meta.(*conns.AWSClient), v))
}
d.Set("vpc", aws.StringValue(address.Domain) == ec2.DomainTypeVpc)

// Force ID to be an Allocation ID if we're on a VPC.
// This allows users to import the EIP based on the IP if they are in a VPC.
Expand Down