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

Applying tags to S3 bucket tries to remove system (aws:*) tags #7323

Closed
dave2 opened this issue Jan 25, 2019 · 4 comments · Fixed by #7342
Closed

Applying tags to S3 bucket tries to remove system (aws:*) tags #7323

dave2 opened this issue Jan 25, 2019 · 4 comments · Fixed by #7342
Labels
bug Addresses a defect in current functionality. service/s3 Issues and PRs that pertain to the s3 service.
Milestone

Comments

@dave2
Copy link

dave2 commented Jan 25, 2019

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

$ terraform -v
Terraform v0.11.10

Note: I have checked the actual code path in github so it should still be affecting terraform even tho I am not on the latest version.

Affected Resource(s)

  • aws_s3_bucket

Terraform Configuration Files

resource "aws_s3_bucket" "example" {
  bucket = "example"
  tags = {
    "some:tag" = "some:value"
  }
}

Debug Output

* aws_s3_bucket.example: "example": InvalidTag: System Tags cannot be removed  by requester

I've included only the error message as the rest of the output is correct (it builds the list of tags provided in the terraform template, and feeds those to the correct API).

Expected Behavior

Bucket has existing aws:* prefix tags due to being created by CloudFormation. These must be preserved over tag updates, because we cannot remove/edit them.

Although the AWS API documentation describes PUT Bucket Tagging as "add tags" this is incorrect, the tag set must be the complete set of tags on the bucket including reserved ones, as any tag not present in the list is implied delete.

API doc is here: https://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUTtagging.html

I've confirmed with AWS that the doc is indeed wrong, and you have to provide existing tags to keep them.

Actual Behavior

Reserved tags are filtered from the incoming list, but not preserved on the update, causing the resource to fail to be updated.

Steps to Reproduce

  1. Create a bucket with CloudFormation
  2. Import the bucket to a terraform resource
  3. Apply any number of tags incl. zero, this will fault with the message in Debug above.

Important Factoids

Nothing magical!

References

AWS API documentation (that is incorrect anyway!): https://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUTtagging.html

@dave2
Copy link
Author

dave2 commented Jan 25, 2019

Note that around L23 in aws/s3_tags.go there are explicit delete and create paths. But the API actually doesn't work this way, and instead you should do read-modify-write on the bucket tags.

https://github.com/terraform-providers/terraform-provider-aws/blob/master/aws/s3_tags.go#L23

@bflad bflad added bug Addresses a defect in current functionality. service/s3 Issues and PRs that pertain to the s3 service. labels Jan 25, 2019
@ewbankkit
Copy link
Contributor

ewbankkit commented Jan 26, 2019

@dave2 Interestingly, you don't get this error if there are also tags to be deleted, in which case https://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketDELETEtagging.html is called first and the system tags are deleted by this call. The subsequent call to https://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUTtagging.html then succeeds but of course the system tags are now lost.
The correct solution is to include any system tags that Terraform ignores when setting S3 bucket tags.

@ghost
Copy link

ghost commented Sep 5, 2019

This has been released in version 2.27.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Nov 1, 2019

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 Nov 1, 2019
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.
Projects
None yet
4 participants