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

resource/aws_s3_bucket_analytics_configuration: Check resource.TimeoutError on deletion #15529

Merged
merged 1 commit into from
Oct 7, 2020
Merged
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
28 changes: 19 additions & 9 deletions aws/resource_aws_s3_bucket_analytics_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}