From 1dc73147f6af71cf7399703f9ca6dccef8b6d1e5 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Tue, 6 Oct 2020 15:24:14 -0400 Subject: [PATCH] resource/aws_s3_bucket_analytics_configuration: Check resource.TimeoutError on deletion Reference: https://github.com/terraform-providers/terraform-provider-aws/issues/12985 Output from acceptance testing (test failure present on main branch): ``` --- FAIL: TestAccAWSS3BucketAnalyticsConfiguration_WithStorageClassAnalysis_Empty (2.96s) --- PASS: TestAccAWSS3BucketAnalyticsConfiguration_WithFilter_Empty (3.02s) --- PASS: TestAccAWSS3BucketAnalyticsConfiguration_basic (36.11s) --- PASS: TestAccAWSS3BucketAnalyticsConfiguration_WithStorageClassAnalysis_Full (38.05s) --- PASS: TestAccAWSS3BucketAnalyticsConfiguration_WithStorageClassAnalysis_Default (39.12s) --- PASS: TestAccAWSS3BucketAnalyticsConfiguration_removed (58.44s) --- PASS: TestAccAWSS3BucketAnalyticsConfiguration_WithFilter_SingleTag (61.76s) --- PASS: TestAccAWSS3BucketAnalyticsConfiguration_WithFilter_Remove (62.27s) --- PASS: TestAccAWSS3BucketAnalyticsConfiguration_WithFilter_PrefixAndTags (64.30s) --- PASS: TestAccAWSS3BucketAnalyticsConfiguration_WithFilter_MultipleTags (64.43s) --- PASS: TestAccAWSS3BucketAnalyticsConfiguration_WithFilter_Prefix (64.54s) --- PASS: TestAccAWSS3BucketAnalyticsConfiguration_updateBasic (102.92s) ``` --- ...e_aws_s3_bucket_analytics_configuration.go | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/aws/resource_aws_s3_bucket_analytics_configuration.go b/aws/resource_aws_s3_bucket_analytics_configuration.go index e50f771c73e..b4b9e3ef3a2 100644 --- a/aws/resource_aws_s3_bucket_analytics_configuration.go +++ b/aws/resource_aws_s3_bucket_analytics_configuration.go @@ -8,10 +8,12 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/s3" + "github.com/hashicorp/aws-sdk-go-base/tfawserr" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" "github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" + "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource" ) func resourceAwsS3BucketAnalyticsConfiguration() *schema.Resource { @@ -411,28 +413,36 @@ func flattenS3AnalyticsS3BucketDestination(bucketDestination *s3.AnalyticsS3Buck } func waitForDeleteS3BucketAnalyticsConfiguration(conn *s3.S3, bucket, name string, timeout time.Duration) error { + input := &s3.GetBucketAnalyticsConfigurationInput{ + Bucket: aws.String(bucket), + Id: aws.String(name), + } + err := resource.Retry(timeout, func() *resource.RetryError { - input := &s3.GetBucketAnalyticsConfigurationInput{ - Bucket: aws.String(bucket), - Id: aws.String(name), - } - log.Printf("[DEBUG] Reading S3 bucket analytics configuration: %s", input) output, err := conn.GetBucketAnalyticsConfiguration(input) + if err != nil { - if isAWSErr(err, s3.ErrCodeNoSuchBucket, "") || isAWSErr(err, "NoSuchConfiguration", "The specified configuration does not exist.") { - return nil - } return resource.NonRetryableError(err) } - if output.AnalyticsConfiguration != nil { + + if output != nil && output.AnalyticsConfiguration != nil { return resource.RetryableError(fmt.Errorf("S3 bucket analytics configuration exists: %v", output)) } return nil }) + if tfresource.TimedOut(err) { + _, err = conn.GetBucketAnalyticsConfiguration(input) + } + + if tfawserr.ErrCodeEquals(err, s3.ErrCodeNoSuchBucket) || tfawserr.ErrMessageContains(err, "NoSuchConfiguration", "The specified configuration does not exist.") { + return nil + } + if err != nil { return fmt.Errorf("error deleting S3 Bucket Analytics Configuration \"%s:%s\": %w", bucket, name, err) } + return nil }