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

r/aws_s3_bucket_object: Delete S3 objects with leading '/' in the key name #7268

Merged
merged 1 commit into from
Jan 25, 2019

Conversation

ewbankkit
Copy link
Contributor

Fixes #7262.
Acceptance tests:

$ make testacc TEST=./aws/ TESTARGS='-run=TestAccAWSS3BucketObject_'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws/ -v -parallel 20 -run=TestAccAWSS3BucketObject_ -timeout 120m
=== RUN   TestAccAWSS3BucketObject_source
=== PAUSE TestAccAWSS3BucketObject_source
=== RUN   TestAccAWSS3BucketObject_content
=== PAUSE TestAccAWSS3BucketObject_content
=== RUN   TestAccAWSS3BucketObject_contentBase64
=== PAUSE TestAccAWSS3BucketObject_contentBase64
=== RUN   TestAccAWSS3BucketObject_withContentCharacteristics
=== PAUSE TestAccAWSS3BucketObject_withContentCharacteristics
=== RUN   TestAccAWSS3BucketObject_updates
=== PAUSE TestAccAWSS3BucketObject_updates
=== RUN   TestAccAWSS3BucketObject_updatesWithVersioning
=== PAUSE TestAccAWSS3BucketObject_updatesWithVersioning
=== RUN   TestAccAWSS3BucketObject_kms
=== PAUSE TestAccAWSS3BucketObject_kms
=== RUN   TestAccAWSS3BucketObject_sse
=== PAUSE TestAccAWSS3BucketObject_sse
=== RUN   TestAccAWSS3BucketObject_acl
=== PAUSE TestAccAWSS3BucketObject_acl
=== RUN   TestAccAWSS3BucketObject_storageClass
=== PAUSE TestAccAWSS3BucketObject_storageClass
=== RUN   TestAccAWSS3BucketObject_tags
=== PAUSE TestAccAWSS3BucketObject_tags
=== RUN   TestAccAWSS3BucketObject_tagsLeadingSlash
=== PAUSE TestAccAWSS3BucketObject_tagsLeadingSlash
=== CONT  TestAccAWSS3BucketObject_source
=== CONT  TestAccAWSS3BucketObject_sse
=== CONT  TestAccAWSS3BucketObject_updates
=== CONT  TestAccAWSS3BucketObject_kms
=== CONT  TestAccAWSS3BucketObject_updatesWithVersioning
=== CONT  TestAccAWSS3BucketObject_contentBase64
=== CONT  TestAccAWSS3BucketObject_withContentCharacteristics
=== CONT  TestAccAWSS3BucketObject_tags
=== CONT  TestAccAWSS3BucketObject_tagsLeadingSlash
=== CONT  TestAccAWSS3BucketObject_storageClass
=== CONT  TestAccAWSS3BucketObject_acl
=== CONT  TestAccAWSS3BucketObject_content
--- PASS: TestAccAWSS3BucketObject_content (41.44s)
--- PASS: TestAccAWSS3BucketObject_contentBase64 (42.68s)
--- PASS: TestAccAWSS3BucketObject_sse (51.63s)
--- PASS: TestAccAWSS3BucketObject_source (56.85s)
--- PASS: TestAccAWSS3BucketObject_withContentCharacteristics (59.55s)
--- PASS: TestAccAWSS3BucketObject_updatesWithVersioning (67.73s)
--- PASS: TestAccAWSS3BucketObject_updates (80.04s)
--- PASS: TestAccAWSS3BucketObject_kms (81.44s)
--- PASS: TestAccAWSS3BucketObject_acl (99.53s)
--- PASS: TestAccAWSS3BucketObject_storageClass (110.67s)
--- PASS: TestAccAWSS3BucketObject_tagsLeadingSlash (112.03s)
--- PASS: TestAccAWSS3BucketObject_tags (129.18s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	130.488s

@ghost ghost added size/M Managed by automation to categorize the size of a PR. service/s3 Issues and PRs that pertain to the s3 service. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Jan 23, 2019
@bflad bflad added the bug Addresses a defect in current functionality. label Jan 25, 2019
@bflad bflad added this to the v1.57.0 milestone Jan 25, 2019
Copy link
Contributor

@bflad bflad left a 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, "/") {
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

bflad added a commit that referenced this pull request Jan 25, 2019
@bflad bflad merged commit 7752d3d into hashicorp:master Jan 25, 2019
@ewbankkit ewbankkit deleted the issue-7262 branch January 25, 2019 18:51
@ewbankkit
Copy link
Contributor Author

@bflad Given that we have been treating S3 objects with keys like /a as a even though they are separate objects when viewed in the AWS Console or via the AWS CLI do we want to add a note to the documentation and maybe add a boolean (default = false) attribute like support_leading_slash - strawman name - equivalent to the SDK's DisableRestProtocolURICleaning property?
Otherwise there is no way to truly support objects whose keys have a leading '/'.

@bflad
Copy link
Contributor

bflad commented Jan 26, 2019

@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.

@ghost
Copy link

ghost commented Apr 1, 2020

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!

@ghost ghost locked and limited conversation to collaborators Apr 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/s3 Issues and PRs that pertain to the s3 service. size/M Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws_s3_bucket_object is destroyed but not deleted
2 participants