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 fix case when aws returns multiple eips from read request #5331

Merged
merged 1 commit into from Jul 30, 2018
Merged
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
20 changes: 13 additions & 7 deletions aws/resource_aws_eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,22 @@ func resourceAwsEipRead(d *schema.ResourceData, meta interface{}) error {
}
}

// Verify AWS returned our EIP
if len(describeAddresses.Addresses) != 1 ||
domain == "vpc" && *describeAddresses.Addresses[0].AllocationId != id ||
*describeAddresses.Addresses[0].PublicIp != id {
if err != nil {
return fmt.Errorf("Unable to find EIP: %#v", describeAddresses.Addresses)
var address *ec2.Address

// In the case that AWS returns more EIPs than we intend it to, we loop
// over the returned addresses to see if it's in the list of results
for _, addr := range describeAddresses.Addresses {
if (domain == "vpc" && aws.StringValue(addr.AllocationId) == id) || aws.StringValue(addr.PublicIp) == id {
address = addr
break
}
}

address := describeAddresses.Addresses[0]
if address == nil {
log.Printf("[WARN] EIP %q not found, removing from state", d.Id())
d.SetId("")
return nil
}

d.Set("association_id", address.AssociationId)
if address.InstanceId != nil {
Expand Down