-
Hi again, everyone! Need some advice or best practise tips on how it would be best to configure code generation for a module that is required to be iterated. For example:
One solution would be to pass the Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You could do the for each evaluation itself using a globals {
items = [
{
name = "foobar"
}
]
}
generate_hcl "_module.tf" {
lets {
item_map = {
for item in global.items : item.name => item
}
}
content {
module "this" {
for_each = let.item_map
source = "some.source"
name = each.value.name
}
}
} Will generate this: module "this" {
for_each = {
foobar = {
name = "foobar"
}
}
name = each.value.name
source = "some.source"
} Which should work. Let me know if I got something wrong or this was helpful. |
Beta Was this translation helpful? Give feedback.
You could do the for each evaluation itself using a
lets
block and then just reference the results on the for_each. Today it is a limitation that you can't have a obj/list comprehension when partial evaluation is involved (which happens inside the content block), but thelets
block is fully evaluated (likeglobals
). So this:Will generate this: