diff --git a/aws/resource_aws_eip.go b/aws/resource_aws_eip.go index 94a951fb196..b794d3ed32f 100644 --- a/aws/resource_aws_eip.go +++ b/aws/resource_aws_eip.go @@ -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 {