Skip to content

Commit

Permalink
r/resource_aws_eip: implement retry reading EIPs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergiusz Urbaniak authored and radeksimko committed Jul 18, 2017
1 parent e3ec558 commit e4244f8
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions aws/resource_aws_eip.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,37 @@ func resourceAwsEipRead(d *schema.ResourceData, meta interface{}) error {
"[DEBUG] EIP describe configuration: %s (domain: %s)",
req, domain)

describeAddresses, err := ec2conn.DescribeAddresses(req)
if err != nil {
if ec2err, ok := err.(awserr.Error); ok && (ec2err.Code() == "InvalidAllocationID.NotFound" || ec2err.Code() == "InvalidAddress.NotFound") {
d.SetId("")
var err error
var describeAddresses *ec2.DescribeAddressesOutput

if d.IsNewResource() {
err := resource.Retry(15*time.Minute, func() *resource.RetryError {
describeAddresses, err = ec2conn.DescribeAddresses(req)
if err != nil {
awsErr, ok := err.(awserr.Error)
if ok && (awsErr.Code() == "InvalidAllocationID.NotFound" ||
awsErr.Code() == "InvalidAddress.NotFound") {
return resource.RetryableError(err)
}

return resource.NonRetryableError(err)
}
return nil
})
if err != nil {
return fmt.Errorf("Error retrieving EIP: %s", err)
}
} else {
describeAddresses, err = ec2conn.DescribeAddresses(req)
if err != nil {
awsErr, ok := err.(awserr.Error)
if ok && (awsErr.Code() == "InvalidAllocationID.NotFound" ||
awsErr.Code() == "InvalidAddress.NotFound") {
log.Printf("[WARN] EIP not found, removing from state: %s", req)
return nil
}
return err
}

return fmt.Errorf("Error retrieving EIP: %s", err)
}

// Verify AWS returned our EIP
Expand Down

0 comments on commit e4244f8

Please sign in to comment.