Skip to content

Commit

Permalink
r/aws_eip fix case when aws returns multiple eips from read request
Browse files Browse the repository at this point in the history
  • Loading branch information
acburdine committed Jul 26, 2018
1 parent 5602670 commit e0786db
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 e0786db

Please sign in to comment.