Skip to content

fix: keep references in partly-known collections; expand for_each over locals with apply-time values - #290

Closed
ezaz-khan-apex wants to merge 1 commit into
cloud-custodian:mainfrom
ezaz-khan-apex:fix/partial-collections-and-for-each-locals
Closed

ezaz-khan-apex wants to merge 1 commit into
cloud-custodian:mainfrom
ezaz-khan-apex:fix/partial-collections-and-for-each-locals

Conversation

@ezaz-khan-apex

Copy link
Copy Markdown

Fixes two cases where tfparse dropped information Terraform has:

  1. Unknown elements of a list/object literal serialized as null (Unknown elements of a list/object literal serialize as null, losing the reference #288). A partly-known TupleConsExpr/ObjectConsExpr is now converted element by element. An unknown element that is a reference gets the same {"__attribute__": …} marker a top-level reference already gets, and its known siblings are unchanged. Object keys must be literals; anything else keeps the previous conversion. A value that reaches the attribute through a local is still a single marker, as before.
  2. for_each over a local with known keys but apply-time values was never expanded (for_each over a local with known keys but apply-time values is never expanded #289). The fix is in the trivy fork, fix: expand for_each over a local whose keys are known but values are not trivy#23. go.mod pins that branch (ezaz-khan-apex/trivy) for now, so CI exercises it; please re-pin to cloud-custodian/trivy once 🌱 Bump pytest-terraform from 0.6.1 to 0.6.4 #23 lands, as fix: resolve for_each and data references #285 did with 🌱 Bump black from 22.6.0 to 22.8.0 #22.

Tests:

  • test_partial_collection_keeps_unknown_references (fixture partial-collection-references) gets null on 0.6.22.
  • test_for_each_over_local_with_unknown_values (fixture for-each-local-unknown-values) gets an unexpanded node on 0.6.22.
  • The full suite passes locally (29 tests). black and flake8 are clean.

For context: on a ~2,100-root Terraform repo, the two fixes together expand 156 more for_each instances, and no existing value changes.

Closes #288
Closes #289

🤖 Generated with Claude Code

…r locals with apply-time values

1. A list or object literal holding one apply-time value (a resource attribute,
   a module output) was serialized with that element as null, which reads as an
   explicit null and loses the reference. Each such element now carries the same
   {"__attribute__": ...} marker a top-level reference gets; known siblings are
   unchanged.

2. A for_each over a local whose keys are known but whose values hold apply-time
   attributes was never expanded. Terraform expands it, since the keys are known.
   Fixed in the trivy fork (cloud-custodian/trivy PR, pinned here from
   ezaz-khan-apex/trivy until it lands).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@ezaz-khan-apex

Copy link
Copy Markdown
Author

Withdrawing this PR and leaving the fixes to the maintainers. The issues stay open: #288 and #289.

@ezaz-khan-apex
ezaz-khan-apex deleted the fix/partial-collections-and-for-each-locals branch October 6, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant