-
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
[Bug]: When trying to create a tag with an empty string as value, other tags are deleted. (provider version >= 5.0.0) #31941
Comments
Community NoteVoting for Prioritization
Volunteering to Work on This Issue
|
This appears to be more widespread than just S3 - I've also seen this issue affecting the following resources:
Presence of tags are used for all sorts of things, so having TF silently deleting them all is quite impactful. The TF plan says it's going to add tags, the apply succeeds and says:
but then all the tags on the resource (existing and new) are deleted. |
Thanks for the additional testimony. However, this problem is happening in all resources, and there seems to be a bug in the process of setting |
This doesn't seem to be an issue with all resources. I can replicate the issue with A particularly interesting INFO log line is (
Full reproduction code and output below. You can see that everything applies correctly, and on the second plan it attempts again to add the tag to the bucket but not to the SNS topic. I have redacted my AWS account ID to 999999999. # main.tf
resource "aws_s3_bucket" "this" {
bucket = "4c59cf5d-0310-4b37-be46-a34e90f065f1"
tags = {
Project = ""
}
}
resource "aws_sns_topic" "this" {
name = "4fa33a6b-2c7a-41c9-9f05-e30176276ce8"
tags = {
Project = ""
}
}
|
A bit of further information, it seems like the bug was originally introduced in v3.38.0. In v3.37.0 it performs as expected, adding the empty tag to both S3 buckets and SNS topics (I'm assuming all resources but I've only tested those two). In v3.38.0 I get the same behaviour as explained above. I did not test every version in between v3.38.0 and v5.6.1 but those that I did test also showed the same broken behaviour. So in my understanding v3.38.0 introduced the bug and v5.0.0 did not fix it as #24449 suggests it did. At first glance of the changelog for v3.38.0 the most likely candidates could be #18958 or #19084. I may attempt to bisect through the commits to confirm if I find the time. |
I have managed to run through a bisect and identified the commit that introduced the issue to be 0578e55. I'm aware that a lot has changed in the design of the repository since then and #24449 did something that attempted to fix the issue. I think I'm at my limit here, that commit is massive and I don't think I can identify the culprit. I keep thinking about it but good luck to whoever can manage to dive into that. I hope this isn't considered rude, tagging those that seem to be involved in that issue so perhaps they may be able to chime in. Much appreciated if you can help, folks @petarlishov @justinretzolk @johnsonaj . |
Hi @oarmstrong, thank you for the investigation and updates! With the release of The AWS API implements resource tagging pretty generically across most services, however there are a few resources where the provider implements custom tagging functions, allowing it to work correctly. These services include resources in the following:
We are working on a plan to update and include these resources in the new tagging process. At this moment we do not have a projected ETA but we will keep this issue updated with any progress/PRs. |
Thanks a lot for the info. That makes sense, it was fixed for all resources except those you listed. Worth noting that a few comments up it was pointed out that Lambda Functions seem to exhibit this issue as well and aren't included in your list (#31941 (comment)). I haven't independently verified that myself. Is there a place where these discussions are occurring for these resources? I wouldn't mind taking a stab at resolving this for S3 buckets (as that's what's currently blocking me at work) but I don't want to waste effort if it doesn't line up with the plan for the bigger picture or if that work is already in progress by someone else. |
Hi! 👋 I want to add ABAC exists: https://docs.aws.amazon.com/organizations/latest/userguide/orgs_tagging_abac.html This bug could actually be the source of big dysfunctions or security issues if people applies inadvertently. Big blocker in my case :( Thanks! |
Hi There, Is there any update on the fix ? |
I'm seeing this with From our plan, you can see the tags need to be added:
In our logs:
I'm currently blocked by this as I can't get my service to connect to consul now. I'm also not sure how to revert to an old provider version at this point. If anyone is aware of a work around, I'd appreciate it. |
Additional resources that are affected:
A workaround I found that got me past the line is to simply use the null type instead of empty strings and this gets past the v5.x.x provider version bug. You can't downgrade the provider version so this seemed to be a better workaround than supplying a dummy value which may cause issues of its own. As the documentation suggests, a null type acts as an omission so the offending tag in question won't get passed to the tag map tags_all at all:
ref: Types and Values |
Was facing this issue when applying empty string tags at any level be it:
I've found the issue goes away and get an |
I spent some time over the holiday break digging into this. I set up a bunch of tests in multiple places that I thought this could be and was able to rule out any code inside of the AWS Terraform Provider. I ultimately traced this bug to a function call in /internal/verify/diff.go in the SetTagsDiff function that starts at line 24. I wired up the code to identify where and how the data was being manipulated and ultimately found that this may be a bug in the upstream terraform-plugin-sdk. I have a forked branch that I set up a print statements before and after line 50 which looks like the following:
and wrote a test that captured the above use case of a populated tag to null tag which then translated to this output when the test ran:
The expected output of a null tag failed due to the return of an empty map. I am going to attempt to find out what is happening in SetNewComputed in the terraform-plugin-sdk that is causing the function to return an empty map which seems to be the root of this issue. |
+1 |
…t. Known terraform issue. See hashicorp/terraform-provider-aws#31941
…t. Known terraform issue. See hashicorp/terraform-provider-aws#31941 (#62)
This functionality has been released in v5.40.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. Thank you! |
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. |
Terraform Core Version
1.4.5, 1.5.0
AWS Provider Version
>= 5.0.0
Affected Resource(s)
ALL
Expected Behavior
When adding a tag with an empty string, I think it shouldn't affect an existing tag, even if the tag isn't actually being created.
Actual Behavior
From aws provider version
5.0.0 or later
, when adding a tag with an empty string value, no tag information is reflected in tags_all, and all existing tags disappear when actually applied.When apply is actually run for the above Plans, new tags are not visible and existing tags are deleted, as shown in
tags_all
.Relevant Error/Panic Output Snippet
No response
Terraform Configuration Files
Steps to Reproduce
{any=""}
to the tag of any resource.Debug Output
No response
Panic Output
No response
Important Factoids
I tested it in
aws_s3_bucket
,aws_security_group
.References
No response
Would you like to implement a fix?
None
The text was updated successfully, but these errors were encountered: