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

Final retry after timeout deleting customer gateway #9421

Merged
merged 1 commit into from
Jul 24, 2019
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
55 changes: 38 additions & 17 deletions aws/resource_aws_customer_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,7 @@ func resourceAwsCustomerGatewayDelete(d *schema.ResourceData, meta interface{})
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidCustomerGatewayID.NotFound" {
return nil
} else {
log.Printf("[ERROR] Error deleting CustomerGateway: %s", err)
return err
return fmt.Errorf("[ERROR] Error deleting CustomerGateway: %s", err)
}
}

Expand All @@ -248,31 +247,53 @@ func resourceAwsCustomerGatewayDelete(d *schema.ResourceData, meta interface{})
Values: []*string{aws.String(d.Id())},
}

input := &ec2.DescribeCustomerGatewaysInput{
Filters: []*ec2.Filter{gatewayFilter},
}
err = resource.Retry(5*time.Minute, func() *resource.RetryError {
resp, err := conn.DescribeCustomerGateways(&ec2.DescribeCustomerGatewaysInput{
Filters: []*ec2.Filter{gatewayFilter},
})
resp, err := conn.DescribeCustomerGateways(input)

if err != nil {
if awserr, ok := err.(awserr.Error); ok && awserr.Code() == "InvalidCustomerGatewayID.NotFound" {
if isAWSErr(err, "InvalidCustomerGatewayID.NotFound", "") {
return nil
}
return resource.NonRetryableError(err)
}

if len(resp.CustomerGateways) != 1 {
return resource.RetryableError(fmt.Errorf("Error finding CustomerGateway for delete: %s", d.Id()))
err = checkGatewayDeleteResponse(resp, d.Id())
if err != nil {
return resource.RetryableError(err)
}
return nil
})

switch *resp.CustomerGateways[0].State {
case "pending", "available", "deleting":
return resource.RetryableError(fmt.Errorf("Gateway (%s) in state (%s), retrying", d.Id(), *resp.CustomerGateways[0].State))
case "deleted":
return nil
default:
return resource.RetryableError(fmt.Errorf("Unrecognized state (%s) for Customer Gateway delete on (%s)", *resp.CustomerGateways[0].State, d.Id()))
if isResourceTimeoutError(err) {
var resp *ec2.DescribeCustomerGatewaysOutput
resp, err = conn.DescribeCustomerGateways(input)

if err != nil {
return checkGatewayDeleteResponse(resp, d.Id())
}
})
}

if err != nil {
return fmt.Errorf("Error deleting customer gateway: %s", err)
}
return nil

}

func checkGatewayDeleteResponse(resp *ec2.DescribeCustomerGatewaysOutput, id string) error {
if len(resp.CustomerGateways) != 1 {
return fmt.Errorf("Error finding CustomerGateway for delete: %s", id)
}

return err
switch *resp.CustomerGateways[0].State {
case "pending", "available", "deleting":
return fmt.Errorf("Gateway (%s) in state (%s), retrying", id, *resp.CustomerGateways[0].State)
case "deleted":
return nil
default:
return fmt.Errorf("Unrecognized state (%s) for Customer Gateway delete on (%s)", *resp.CustomerGateways[0].State, id)
}
}