When a module's for_each uses a for expression (e.g. { for k in var.list : k.name => k }), checkov stores it as a literal string and never expands the module. Direct map/set references work correctly.
Minimal reproducer (2 files)
modules/child/main.tf
variable "val" { type = string }
resource "terraform_data" "test" { input = var.val }
main.tf
variable "items" {
type = list(string)
default = ["a", "b"]
}
module "child" {
source = "./modules/child"
for_each = { for v in var.items : v => v }
val = each.value
}
Expected
Module expands to child["a"] and child["b"], resource resolves input.
Actual
Module child is not expanded. for_each stored as string:
"{for v in ['a', 'b'] : v :> v}"
Workaround
Use a direct map reference instead of a for expression:
variable "items" {
type = map(string)
default = { a = "a", b = "b" }
}
module "child" {
source = "./modules/child"
for_each = var.items
val = each.value
}
This expands child["a"] and child["b"] correctly.
Environment
Verified on main (8bd89be03). terraform validate passes on the reproducer.
When a module's
for_eachuses aforexpression (e.g.{ for k in var.list : k.name => k }), checkov stores it as a literal string and never expands the module. Direct map/set references work correctly.Minimal reproducer (2 files)
modules/child/main.tf
main.tf
Expected
Module expands to
child["a"]andchild["b"], resource resolvesinput.Actual
Module
childis not expanded.for_eachstored as string:Workaround
Use a direct map reference instead of a
forexpression:This expands
child["a"]andchild["b"]correctly.Environment
Verified on main (
8bd89be03).terraform validatepasses on the reproducer.