-
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
r/aws_s3_bucket_object: Delete S3 objects with leading '/' in the key name #7268
Conversation
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.
Looks good to me, thanks for your quick fix @ewbankkit!
Before code update, test fails as expected:
--- FAIL: TestAccAWSS3BucketObject_tagsLeadingSlash (76.28s)
testing.go:599: Error destroying resource! WARNING: Dangling resources
may exist. The full state and error is shown below.
Error: Error applying: 1 error occurred:
* aws_s3_bucket.object_bucket (destroy): 1 error occurred:
* aws_s3_bucket.object_bucket: error deleting S3 Bucket (tf-object-test-bucket-3900350678782068183): BucketNotEmpty: The bucket you tried to delete is not empty. You must delete all versions in the bucket.
After code update:
--- PASS: TestAccAWSS3BucketObject_tagsLeadingSlash (79.14s)
@@ -385,6 +385,11 @@ func resourceAwsS3BucketObjectDelete(d *schema.ResourceData, meta interface{}) e | |||
|
|||
bucket := d.Get("bucket").(string) | |||
key := d.Get("key").(string) | |||
// We are effectively ignoring any leading '/' in the key name as aws.Config.DisableRestProtocolURICleaning is false | |||
// so we need to explicitly ignore any leading '/' in the s3.ListObjectVersions call. | |||
if strings.HasPrefix(key, "/") { |
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.
FYI this will likely be updated as part of #7240 to just use strings.TrimPrefix()
-- see also https://staticcheck.io/docs/checks#S1017
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.
👍
@bflad Given that we have been treating S3 objects with keys like |
@ewbankkit the note certainly sounds worthwhile but as for managing objects with the leading slash I would encourage waiting for specific asks since it seems like it could be an esoteric use case This has been released in version 1.57.0 of the AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Fixes #7262.
Acceptance tests: