Skip to content

Add tagging support for google_container_cluster using resource_labels#698

Open
yhengly wants to merge 1 commit intobridgecrewio:mainfrom
yhengly:main
Open

Add tagging support for google_container_cluster using resource_labels#698
yhengly wants to merge 1 commit intobridgecrewio:mainfrom
yhengly:main

Conversation

@yhengly
Copy link
Copy Markdown

@yhengly yhengly commented Apr 27, 2026

Summary

Adds support for tagging google_container_cluster resources. This resource uses resource_labels as its tag attribute instead of the standard labels used 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., googlelabels). However, google_container_cluster uses resource_labels for its tags, not labels. Without this change, Yor either skips the resource or writes tags to the wrong attribute.

Changes

  • src/terraform/structure/terraform_block.go — Added ResourceTypeToTagAttribute map to override the provider-level tag attribute for specific resource types (google_container_clusterresource_labels)
  • src/terraform/structure/terraform_parser.go — Modified getTagAttributeByResourceType() to check the resource-type override map before falling back to the provider default
  • src/terraform/structure/tf_taggable.go — Added google_container_cluster to TfTaggableResourceTypes
  • tests/terraform/resources/gke/main.tf — Test fixture with tagged and untagged google_container_cluster resources
  • src/terraform/structure/terraform_parser_test.go — Parser test verifying taggability, correct attribute name (resource_labels), and tag extraction
  • src/terraform/structure/terraform_block_test.go — Block tests verifying IsGCPBlock() detection and ResourceTypeToTagAttribute override correctness

How It Works

getTagAttributeByResourceType("google_container_cluster")
  → checks ResourceTypeToTagAttribute → finds "resource_labels" → returns it

getTagAttributeByResourceType("google_storage_bucket")
  → checks ResourceTypeToTagAttribute → not found
  → falls back to ProviderToTagAttribute["google"] → returns "labels"

Testing

  • Functional test: go run main.go tag -d tests/terraform/resources/gke --dry-run -o json confirms both resources are detected and tagged under resource_labels
  • Full regression: scanning tests/terraform/resources/ (67 resources across AWS/GCP/modules) completes with zero errors
  • Backward-compatible: all existing resources continue using their provider-level tag attribute mapping

Extensibility

Future GCP resources with non-standard tag attributes (e.g., google_container_node_pool also uses resource_labels) can be added with a single line in the ResourceTypeToTagAttribute map.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant