Skip to content

fix(terraform): evaluate for expressions in module for_each#7505

Open
pszypowicz wants to merge 1 commit intobridgecrewio:mainfrom
pszypowicz:worktree-fluffy-discovering-pretzel
Open

fix(terraform): evaluate for expressions in module for_each#7505
pszypowicz wants to merge 1 commit intobridgecrewio:mainfrom
pszypowicz:worktree-fluffy-discovering-pretzel

Conversation

@pszypowicz
Copy link
Copy Markdown

Summary

Fixes #7503

When a module's for_each uses a for expression with a simple identity mapping (e.g. { for v in var.items : v => v }), _handle_for_loop_in_dict() assumed iterable items are always dicts and tried obj[k_expression], which raises TypeError on string items. The module was silently skipped.

  • Handle the case where the key expression equals the loop variable by using the item directly as the dict key
  • Add unit test for the for-expression evaluation
  • Add integration test verifying module expansion with a for expression in for_each

Test plan

  • New unit test: test_handle_for_loop_in_dict_with_simple_iterable -- {for v in ['a', 'b'] : v => v} evaluates to {'a': 'a', 'b': 'b'}
  • New integration test: test_foreach_module_with_for_expression -- module with for_each = { for v in var.items : v => v } expands to child["a"] and child["b"]
  • Full tests/terraform/graph/variable_rendering/ suite passes (207 passed, 0 failed)

…ewio#7503)

When a module's for_each uses a for expression with a simple identity
mapping like { for v in var.items : v => v }, the expression evaluator
assumed iterable items are always dicts and tried obj[k_expression],
which fails with TypeError on string items. Handle the case where the
key expression is the loop variable itself by using the item directly.
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.

Module for_each with for expression is not evaluated

1 participant