From f0fab36818783f87e172911109130f5660361909 Mon Sep 17 00:00:00 2001 From: Ryn Daniels Date: Tue, 6 Aug 2019 16:35:46 +0200 Subject: [PATCH] Final retry after timeout deleting vpc --- aws/resource_aws_vpc.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/aws/resource_aws_vpc.go b/aws/resource_aws_vpc.go index 5e07be0af68..f0a12162622 100644 --- a/aws/resource_aws_vpc.go +++ b/aws/resource_aws_vpc.go @@ -478,26 +478,31 @@ func resourceAwsVpcDelete(d *schema.ResourceData, meta interface{}) error { } log.Printf("[INFO] Deleting VPC: %s", d.Id()) - return resource.Retry(5*time.Minute, func() *resource.RetryError { + err := resource.Retry(5*time.Minute, func() *resource.RetryError { _, err := conn.DeleteVpc(deleteVpcOpts) if err == nil { return nil } - ec2err, ok := err.(awserr.Error) - if !ok { - return resource.NonRetryableError(err) - } - - switch ec2err.Code() { - case "InvalidVpcID.NotFound": + if isAWSErr(err, "InvalidVpcID.NotFound", "") { return nil - case "DependencyViolation": + } + if isAWSErr(err, "DependencyViolation", "") { return resource.RetryableError(err) } - return resource.NonRetryableError(fmt.Errorf("Error deleting VPC: %s", err)) }) + if isResourceTimeoutError(err) { + _, err = conn.DeleteVpc(deleteVpcOpts) + if isAWSErr(err, "InvalidVpcID.NotFound", "") { + return nil + } + } + + if err != nil { + return fmt.Errorf("Error deleting VPC: %s", err) + } + return nil } func resourceAwsVpcCustomizeDiff(diff *schema.ResourceDiff, v interface{}) error {