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

[Bug]: terraform apply failed to remove resource's tag from state #31695

Closed
44smkn opened this issue Jun 1, 2023 · 5 comments · Fixed by #31826
Closed

[Bug]: terraform apply failed to remove resource's tag from state #31695

44smkn opened this issue Jun 1, 2023 · 5 comments · Fixed by #31826
Assignees
Labels
bug Addresses a defect in current functionality. service/iam Issues and PRs that pertain to the iam service. tags Pertains to resource tagging.
Milestone

Comments

@44smkn
Copy link

44smkn commented Jun 1, 2023

Terraform Core Version

1.4.6

AWS Provider Version

5.0.1

Affected Resource(s)

  • aws_iam_role

Expected Behavior

We removed Environment and Product of the resource's tags and moved them to default_tags.
terraform plan showed that they are removed from tags and added to tags_all.
We expected terraform apply to reflect that change to the state file.

Plan

  # aws_iam_role.sample will be updated in-place
  ~ resource "aws_iam_role" "sample" {
        id                    = "sample"
        name                  = "sample"
      ~ tags                  = {
          - "Environment" = "foo" -> null
            "ManagedBy"   = "Terraform"
          - "Product"     = "bar" -> null
        }
        # (11 unchanged attributes hidden)

        # (2 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Actual Behavior

We found that terraform apply failed to remove resource's tag from the state file.
So, terraform plan always shows the deletion of the resource's tag.

Relevant Error/Panic Output Snippet

None

Terraform Configuration Files

resource "aws_iam_role" "sample" {
  name               = "sample"
  tags = {
    ManagedBy = "Terraform"
  }
}

locals {
  region         = "ap-northeast-1"
  environment    = "foo"
  product        = "bar"
}

provider "aws" {
  default_tags {
    tags = {
      Environment    = local.environment
      Product        = local.product
    }
  }
  region      = local.region
}

Steps to Reproduce

I wonder if this can be reproduced when some keys are removed from tags when tags and default_tags declared.

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

@44smkn 44smkn added bug Addresses a defect in current functionality. needs-triage Waiting for first response or review from a maintainer. labels Jun 1, 2023
@github-actions
Copy link

github-actions bot commented Jun 1, 2023

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • 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.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added the service/iam Issues and PRs that pertain to the iam service. label Jun 1, 2023
@ewbankkit ewbankkit added the tags Pertains to resource tagging. label Jun 1, 2023
@justinretzolk justinretzolk removed the needs-triage Waiting for first response or review from a maintainer. label Jun 1, 2023
@johnsonaj johnsonaj assigned johnsonaj and unassigned johnsonaj Jun 1, 2023
@ewbankkit
Copy link
Contributor

ewbankkit commented Jun 1, 2023

Because IAM has per-resource tagging functions rather than per-service, we cannot use the generic code in the tagging interceptor and these resources aren't getting the benefit of the default_tags work done in v5.0.0.

@nathanpreen
Copy link

Hey, I'm seeing this behaviour on several other resources also. Will list them below.

aws_kms_key
aws_security_group
aws_acm_certificate
aws_launch_template

@johnsonaj johnsonaj self-assigned this Jun 5, 2023
@github-actions github-actions bot added this to the v5.2.0 milestone Jun 7, 2023
@github-actions
Copy link

github-actions bot commented Jun 9, 2023

This functionality has been released in v5.2.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 Jul 10, 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/iam Issues and PRs that pertain to the iam service. tags Pertains to resource tagging.
Projects
None yet
5 participants