You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
terraform TF020 misses a reference nested more than six levels deep in a block #5107
TF020 reports a local as "declared and never referenced" when its only reference sits several blocks down, such as the expression of a Cloud Armor rule's match { expr { ... } }. referencesInBody in lexicons/terraform/src/hcl/references.ts walks the hcl2json body and returns at depth > 6. hcl2json gives each nested block as an array of objects, so rule, match and expr use six levels and the expression string is the seventh, which is never scanned. The same reference inside an interpolation at the top level of the block is found, so string interpolation is not the cause. On kubernetes/k8s.io this gave TF020 for local.allowed_paths in infra/gcp/terraform/modules/oci-proxy/cloud-armor.tf, once for each root that calls the module.
Reproduce
Run with chant 0.124.95 from npm and @cdktn/hcl2json.
tree/root/main.tf holds a terraform block with a backend and required_providers, and module "m" { source = "../mod" }.
chant audit tree --format json --tier all --fail-on none -o out.json
The report has one TF020, for local.deep, with entity root/module.m/locals. local.shallow is not reported.
Expected
No TF020 for local.deep. The walk reaches every string in the body, or its depth limit is high enough for the blocks providers nest, with a test at the depth of the Cloud Armor rule above.
Where
referencesInBody in lexicons/terraform/src/hcl/references.ts (the if (depth > 6) return; line). TF020 (lexicons/terraform/src/lint/post-synth/tf020.ts) is the only rule that reads this index today.
Found while reading kubernetes/k8s.io offline, for #5067. Tracked on #5105.
Activity
fix(terraform): TF020 reads references at any depth in a block, with …
feat: estate-read batch 3, Terraform and k8s lint precision, Helm ren…