Skip to content

feat: show resources by their Terraform address - #107

Merged
andreacappelletti97 merged 1 commit into
mainfrom
feat/terraform-addresses
Sep 29, 2026
Merged

andreacappelletti97 merged 1 commit into
mainfrom
feat/terraform-addresses

Conversation

@andreacappelletti97

Copy link
Copy Markdown
Contributor

What changes

Resources inside modules are now shown by their Terraform address in every format and PR comment.

Before After
aws_instance.module.tier["web"].this[0] module.tier["web"].aws_instance.this[0]
aws_db_instance.module.a.module.b.main module.a.module.b.aws_db_instance.main
aws_instance.web[0] aws_instance.web[0] (unchanged outside modules)

Label() now returns TerraformAddress(), which already existed for top --format targets. The old form is kept as LegacyLabel(). CSV and the diff formats, which built the string by hand, now use Label().

Compatibility

  • Saved baselines: unaffected. ComputeDiff matches on kind and name, not on the label. TestBaselineFromBeforeTerraformAddressesStillDiffs decodes a pre-change baseline and gets one modified resource, not an added/removed pair.
  • Usage files: Terraform-address keys now match. internal/usage has documented that form (module.frontend.aws_instance.web) all along, but such keys were silently unmatched and their usage ignored. Legacy keys still match, and the CLI warns with the new key to use. If a file has both, the Terraform address wins and the legacy key is reported as unmatched.
  • --what-if: accepts module.web.aws_instance.this[0].instance_type=…, splitting only on dots outside [...], so logs["a.b"] keys work. The legacy form still parses to the same resource, with a warning. An incomplete module address is rejected.
  • JSON: resource changes to the address; kind and name are unchanged. The CHANGELOG calls this out for scripts.

Tests

  • domain: Label equals TerraformAddress, LegacyLabel is kept, and both are identical outside modules.
  • usage: new form, legacy form plus its report, and precedence when both are present.
  • whatif: plain, indexed, nested-module, dotted for_each keys, legacy, and invalid input.
  • render: a pre-change baseline diffs cleanly.
  • golden monorepo-with-modules.md: the only change is the five module labels.

Resources inside modules were labelled kind-first
(aws_instance.module.tier["web"].this[0]), which Terraform does not
accept, in every output and PR comment. Label() now returns the
Terraform address (module.tier["web"].aws_instance.this[0]); the old
form is LegacyLabel().

Usage-file keys and --what-if accept the Terraform address (which the
usage docs already promised; such keys were silently unmatched) and
still accept the old form with a warning. Diffs and baselines match on
kind and name, so saved baselines are unaffected.
@andreacappelletti97
andreacappelletti97 merged commit f5e162f into main Sep 29, 2026
6 checks passed
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