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/resource_aws_eip: implement retry reading EIPs #1053

Merged
merged 1 commit into from
Jul 18, 2017
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
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