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

Setting tags to have empty values or changing tags from having a value to having no value is not correctly handled #24449

Closed
petarlishov opened this issue Apr 28, 2022 · 4 comments
Labels
bug Addresses a defect in current functionality. service/acm Issues and PRs that pertain to the acm service. service/apigateway Issues and PRs that pertain to the apigateway service. service/configservice Issues and PRs that pertain to the configservice service. service/ec2 Issues and PRs that pertain to the ec2 service. service/events Issues and PRs that pertain to the events service. service/firehose Issues and PRs that pertain to the firehose service. service/iam Issues and PRs that pertain to the iam service. service/kms Issues and PRs that pertain to the kms service. service/lambda Issues and PRs that pertain to the lambda service. service/logs Issues and PRs that pertain to the logs service. service/rds Issues and PRs that pertain to the rds service. service/s3 Issues and PRs that pertain to the s3 service. service/secretsmanager Issues and PRs that pertain to the secretsmanager service. service/sns Issues and PRs that pertain to the sns service. service/sqs Issues and PRs that pertain to the sqs service. service/vpc Issues and PRs that pertain to the vpc service. service/wafv2 Issues and PRs that pertain to the wafv2 service. tags Pertains to resource tagging.
Milestone

Comments

@petarlishov
Copy link

petarlishov commented Apr 28, 2022

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 other comments that do not add relevant new information or questions, 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 CLI and Terraform AWS Provider Version

Terraform version 0.14.7
AWS provider version v4.11.0

Affected Resource(s)

Multiple. Examples of this issue have been seen in:

  • aws_acm_certificate
  • aws_api_gateway_api_key
  • aws_api_gateway_domain_name
  • aws_api_gateway_rest_api
  • aws_api_gateway_stage
  • aws_api_gateway_usage_plan
  • aws_cloudwatch_event_rule
  • aws_cloudwatch_log_group
  • aws_config_config_rule
  • aws_db_parameter_group
  • aws_db_proxy
  • aws_db_subnet_group
  • aws_iam_instance_profile
  • aws_iam_role
  • aws_instance
  • aws_kinesis_firehose_delivery_stream
  • aws_kms_key
  • aws_rds_cluster_parameter_group
  • aws_secretsmanager_secret
  • aws_security_group
  • aws_sns_topic
  • aws_sqs_queue
  • aws_wafv2_ip_set
  • aws_wafv2_web_acl
  • aws_lambda_function
  • aws_s3_bucket
  • aws_rds_cluster
  • aws_rds_cluster_instance

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

First scenario:

resource "aws_s3_bucket" "bucket" {
  bucket ="somethingthatisnttaken"
  tags = {
    example = ""
  }
}

Output of terraform plan upon creation:

  # aws_s3_bucket.bucket will be created
   + resource "aws_s3_bucket" "bucket" {
...
       + bucket                      = "somethingthatisnttaken"
...
       + tags                        = {
           + "example" = ""
         }
...

Every subsequent output of terraform plan:

  # aws_s3_bucket.bucket will be updated in-place
  ~ resource "aws_s3_bucket" "bucket" {
        id                          = "somethingthatisnttaken"
      ~ tags                        = {
          + "example" = ""
        }
      ~ tags_all                    = {
          + "example" = ""
        }
        # (9 unchanged attributes hidden)
        # (2 unchanged blocks hidden)
    }
...

Second scenario:

First step:

resource "aws_s3_bucket" "bucket" {
  bucket ="somethingthatisnttaken"
  tags = {
    example = "something"
  }
}

Output:

   + resource "aws_s3_bucket" "bucket" {
...
       + bucket                      = "somethingthatisnttaken"
...
       + tags                        = {
           + "example" = "something"
         }
...

Second step - terraform apply these changes:

resource "aws_s3_bucket" "bucket" {
  bucket ="somethingthatisnttaken"
  tags = {
    example = ""
  }
}

Every subsequent output of terraform plan:

  # aws_s3_bucket.bucket will be updated in-place
  ~ resource "aws_s3_bucket" "bucket" {
        id                          = "somethingthatisnttaken"
      ~ tags                        = {
          ~ "example" = "something" -> ""
        }
        # (10 unchanged attributes hidden)
        # (2 unchanged blocks hidden)
    }
...

Debug Output

I apologise but I cannot get the debug output without some decent amount of research into what needs to be obfuscated in the API calls to AWSand potentially other sensitive information. If you believe this is essential for debugging this issue as you cannot replicate, I will look into what I can do

Panic Output

Expected Behavior

First scenario

Upon the first terraform apply, the S3 bucket should have the "example" tag set with no value.
A subsequent run of terraform apply should not attempt to change the resource from its initial state (the one it was left in after the first terraform apply)

Second scenario

For the first step, upon the first terraform apply, the S3 bucket should have the "example" tag set with the value of "something".
For the second step, upon the terraform apply the S3 bucket should have the "example" tag changed to have no value (not the same as tag deletion)
A subsequent run of terraform apply should not attempt to change the resource from its previous state (the one it was left in after the last terraform apply)

Actual Behavior

First scenario

Upon the first terraform apply, the AWS bucket is created with no tags
Every subsequent run of terraform apply attempts to add the "example" tag but that seems to never happen (no errors shown though, Terraform is happy and assumes that everything went well)

Second scenario

For the first step, everything goes as planned and the S3 bucket is created with the "example" tag set with the value of "something".
For the second step, upon the terraform apply the S3 bucket does not change the state of the "example" tag and it is left with the value of "something"
Every subsequent run of terraform apply attempts to change the "example" tag but that seems to never happen (no errors shown though, Terraform is happy and assumes that everything went well)

Steps to Reproduce

First scenario

  1. terraform apply
  2. terraform apply

Second scenario

  1. terraform apply
  2. change the Terraform configuration to match part 2
  3. terraform apply
  4. terraform apply

Important Factoids

This has been seen on a few really old accounts from what I am aware of so I would not be surprised if this has to do with the account setup. I can have an ask if you know what might be useful to know about (I am not the account owner)

References

@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. service/acm Issues and PRs that pertain to the acm service. service/apigateway Issues and PRs that pertain to the apigateway service. service/configservice Issues and PRs that pertain to the configservice service. service/ec2 Issues and PRs that pertain to the ec2 service. service/events Issues and PRs that pertain to the events service. service/firehose Issues and PRs that pertain to the firehose service. service/iam Issues and PRs that pertain to the iam service. service/kms Issues and PRs that pertain to the kms service. service/lambda Issues and PRs that pertain to the lambda service. service/logs Issues and PRs that pertain to the logs service. service/rds Issues and PRs that pertain to the rds service. service/s3 Issues and PRs that pertain to the s3 service. service/secretsmanager Issues and PRs that pertain to the secretsmanager service. service/sns Issues and PRs that pertain to the sns service. service/sqs Issues and PRs that pertain to the sqs service. service/vpc Issues and PRs that pertain to the vpc service. service/wafv2 Issues and PRs that pertain to the wafv2 service. labels Apr 28, 2022
@justinretzolk justinretzolk added bug Addresses a defect in current functionality. tags Pertains to resource tagging. and removed needs-triage Waiting for first response or review from a maintainer. labels Apr 28, 2022
@petarlishov petarlishov changed the title Setting tags to have empty values or changing tags from having a value to having no value is not correctly handled (might affect "default_tags") Setting tags to have empty values or changing tags from having a value to having no value is not correctly handled Apr 29, 2022
@johnsonaj johnsonaj added this to the v5.0.0 milestone May 11, 2023
@johnsonaj
Copy link
Contributor

Issue was resolved in #30793 and merged to main in #31392. Will be released in v5.0.0

@github-actions
Copy link

This functionality has been released in v5.0.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!

@github-actions
Copy link

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 25, 2023
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/acm Issues and PRs that pertain to the acm service. service/apigateway Issues and PRs that pertain to the apigateway service. service/configservice Issues and PRs that pertain to the configservice service. service/ec2 Issues and PRs that pertain to the ec2 service. service/events Issues and PRs that pertain to the events service. service/firehose Issues and PRs that pertain to the firehose service. service/iam Issues and PRs that pertain to the iam service. service/kms Issues and PRs that pertain to the kms service. service/lambda Issues and PRs that pertain to the lambda service. service/logs Issues and PRs that pertain to the logs service. service/rds Issues and PRs that pertain to the rds service. service/s3 Issues and PRs that pertain to the s3 service. service/secretsmanager Issues and PRs that pertain to the secretsmanager service. service/sns Issues and PRs that pertain to the sns service. service/sqs Issues and PRs that pertain to the sqs service. service/vpc Issues and PRs that pertain to the vpc service. service/wafv2 Issues and PRs that pertain to the wafv2 service. tags Pertains to resource tagging.
Projects
None yet
Development

No branches or pull requests

3 participants