hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.87k stars 9.21k forks source link

[Bug]: Resource tag state reads ignorant of inheritance #31909

Closed dacreify closed 1 year ago

dacreify commented 1 year ago

Terraform Core Version

1.3.7

AWS Provider Version

4.67.0

Affected Resource(s)

Expected Behavior

When tag values are applied at a table or column level, other tag values inherited from the database or table level should be ignored when reading back state.

For example, consider this scenario:

The GetResourceLFTags API call to Lake Formation will have both foo=bar and bam=baz in the LFTagsOnTable structure for my_table. However only bam=baz is applied directly to the table and foo=bar should be ignored for purposes of determining the state of the aws_lakeformation_resource_lf_tags resource with the table {database_name = "my_database", name = "my_table"} block.

Actual Behavior

Terraform perceives state drift on every refresh because it sees the inherited tags and (correctly) identifies that they are not part of the corresponding table/column-level aws_lakeformation_resource_lf_tags resource. All tags of tables and columns with inherited tag values are destroyed and recreated by each plan.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

resource "aws_glue_catalog_database" "database" {
  name = "my_database"
}

resource "aws_glue_catalog_table" "table" {
  database_name = "my_database"
  name          = "my_table"
}

resource "aws_lakeformation_resource_lf_tags" "database_tags" {
  database {
    name = "my_database"
  }

  lf_tag" {
    key   = "foo"
    value = "bar"
  }
}

resource "aws_lakeformation_resource_lf_tags" "table_tags" {
  table {
    database_name = "my_database"
    name          = "my_table"
  }

  lf_tag {
    key   = "bam"
    value = "baz"
  }
}

Steps to Reproduce

Apply and plan again to see phantom state drift

Debug Output

No response

Panic Output

No response

Important Factoids

The response from the GetResourceLFTags Lake Formation API call includes the full inheritance hierarchy for a given table/column via LFTagOnDatabase, LFTagsOnTable, and LFTagsOnColumns. By reducing over these it should be possible to resolve which tag values are being applied at the table/column level and thus resolve accurate state.

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

github-actions[bot] commented 1 year ago

This functionality has been released in v5.6.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[bot] commented 1 year ago

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.