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
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,12 @@ func (c *Config) Client() (interface{}, error) {
r.Retryable = aws.Bool(true)
}
}

if r.Operation.Name == "AttachVpnGateway" {
if isAWSErr(r.Error, "InvalidParameterValue", "This call cannot be completed because there are pending VPNs or Virtual Interfaces") {
r.Retryable = aws.Bool(true)
}
}
})

client.kafkaconn.Handlers.Retry.PushBack(func(r *request.Request) {
Expand Down
37 changes: 23 additions & 14 deletions aws/resource_aws_vpn_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,29 +153,35 @@ 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 {
return resource.RetryableError(err)
}

switch ec2err.Code() {
case "InvalidVpnGatewayID.NotFound":
if isAWSErr(err, "InvalidVpnGatewayID.NotFound", "") {
return nil
case "IncorrectState":
}
if isAWSErr(err, "IncorrectState", "") {
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 @@ -210,9 +216,12 @@ func resourceAwsVpnGatewayAttach(d *schema.ResourceData, meta interface{}) error
}
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