Add tagging support for google_container_cluster using resource_labels#698
Open
yhengly wants to merge 1 commit intobridgecrewio:mainfrom
Open
Add tagging support for google_container_cluster using resource_labels#698yhengly wants to merge 1 commit intobridgecrewio:mainfrom
yhengly wants to merge 1 commit intobridgecrewio:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds support for tagging
google_container_clusterresources. This resource usesresource_labelsas its tag attribute instead of the standardlabelsused by most GCP resources, which required introducing a per-resource-type tag attribute override mechanism.Problem
Yor maps each Terraform provider to a single tag attribute name via
ProviderToTagAttribute(e.g.,google→labels). However,google_container_clusterusesresource_labelsfor its tags, notlabels. Without this change, Yor either skips the resource or writes tags to the wrong attribute.Changes
src/terraform/structure/terraform_block.go— AddedResourceTypeToTagAttributemap to override the provider-level tag attribute for specific resource types (google_container_cluster→resource_labels)src/terraform/structure/terraform_parser.go— ModifiedgetTagAttributeByResourceType()to check the resource-type override map before falling back to the provider defaultsrc/terraform/structure/tf_taggable.go— Addedgoogle_container_clustertoTfTaggableResourceTypestests/terraform/resources/gke/main.tf— Test fixture with tagged and untaggedgoogle_container_clusterresourcessrc/terraform/structure/terraform_parser_test.go— Parser test verifying taggability, correct attribute name (resource_labels), and tag extractionsrc/terraform/structure/terraform_block_test.go— Block tests verifyingIsGCPBlock()detection andResourceTypeToTagAttributeoverride correctnessHow It Works
Testing
go run main.go tag -d tests/terraform/resources/gke --dry-run -o jsonconfirms both resources are detected and tagged underresource_labelstests/terraform/resources/(67 resources across AWS/GCP/modules) completes with zero errorsExtensibility
Future GCP resources with non-standard tag attributes (e.g.,
google_container_node_poolalso usesresource_labels) can be added with a single line in theResourceTypeToTagAttributemap.