-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, "", "") { | ||
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 { | ||
|
@@ -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") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest moving this logic into |
||
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 | ||
|
There was a problem hiding this comment.
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.