I have a module that outputs two values, key and value. The module contains a third value is_needed, which is a boolean. I can run this module any number of times and get a map of the outputs. Is there a way to conditionally add values to a map based on the is_needed boolean?
For example, I can create a map with all of the values like this:
locals {
map_of_values = tomap({
for instance in module.my_module : instance.key => instance.value
})
}
Can I create a map with only some of the values? Something akin to this pseudo-code:
locals {
map_of_needed_values = tomap({
for instance in module.my_module if is_needed: instance.key => instance.value
})
}