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 retries deleting and attaching VPN gateways #9641

Merged
merged 3 commits into from
Aug 9, 2019
Merged
Changes from 1 commit
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
41 changes: 28 additions & 13 deletions aws/resource_aws_vpn_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,29 +153,38 @@ func resourceAwsVpnGatewayDelete(d *schema.ResourceData, meta interface{}) error
}

log.Printf("[INFO] Deleting VPN gateway: %s", d.Id())

return resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.DeleteVpnGateway(&ec2.DeleteVpnGatewayInput{
VpnGatewayId: aws.String(d.Id()),
})
input := &ec2.DeleteVpnGatewayInput{
VpnGatewayId: aws.String(d.Id()),
}
err := resource.Retry(5*time.Minute, func() *resource.RetryError {
_, err := conn.DeleteVpnGateway(input)
if err == nil {
return nil
}

ec2err, ok := err.(awserr.Error)
if !ok {
if isAWSErr(err, "InvalidVpnGatewayID.NotFound", "") {
return nil
}
if isAWSErr(err, "IncorrectState", "") {
return resource.RetryableError(err)
}

switch ec2err.Code() {
case "InvalidVpnGatewayID.NotFound":
return nil
case "IncorrectState":
if !isAWSErr(err, "", "") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a valid error condition to test 😉 All AWS Go SDK errors should have an error code. We can just remove this if condition here.

return resource.RetryableError(err)
}

return resource.NonRetryableError(err)
})
if isResourceTimeoutError(err) {
_, err = conn.DeleteVpnGateway(input)
if isAWSErr(err, "InvalidVpnGatewayID.NotFound", "") {
return nil
}
}

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

func resourceAwsVpnGatewayAttach(d *schema.ResourceData, meta interface{}) error {
Expand Down Expand Up @@ -206,13 +215,19 @@ func resourceAwsVpnGatewayAttach(d *schema.ResourceData, meta interface{}) error
if isAWSErr(err, "InvalidVpnGatewayID.NotFound", "") {
return resource.RetryableError(err)
}
if isAWSErr(err, "InvalidParameterValue", "This call cannot be completed because there are pending VPNs or Virtual Interfaces") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest moving this logic into aws/config.go so we can have the AWS Go SDK automatically retry this API call anywhere its used. See also: https://github.com/terraform-providers/terraform-provider-aws/blob/7cb3734472b25b4515367d55326b88ae480c5937/aws/config.go#L556-L574

return resource.RetryableError(err)
}
return resource.NonRetryableError(err)
}
return nil
})
if isResourceTimeoutError(err) {
_, err = conn.AttachVpnGateway(req)
}

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

// Wait for it to be fully attached before continuing
Expand Down