Skip to content

Commit

Permalink
Merge pull request #5331 from rv-aburdine/fix/eip-filter
Browse files Browse the repository at this point in the history
r/aws_eip fix case when aws returns multiple eips from read request
  • Loading branch information
bflad authored Jul 30, 2018
2 parents fb482e5 + e0786db commit 2ae5370
Showing 1 changed file with 13 additions and 7 deletions.
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

0 comments on commit 2ae5370

Please sign in to comment.