diff --git a/aws/config.go b/aws/config.go index f7e8a4f4d16..76ed9e48d41 100644 --- a/aws/config.go +++ b/aws/config.go @@ -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) { diff --git a/aws/resource_aws_vpn_gateway.go b/aws/resource_aws_vpn_gateway.go index d4006d37c1b..55365ce2671 100644 --- a/aws/resource_aws_vpn_gateway.go +++ b/aws/resource_aws_vpn_gateway.go @@ -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 { @@ -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