Is it possible to dynamically select map variable, e.g?
Currently I am doing this:
vars.tf
locals {
map1 = {
name1 = "foo"
name2 = "bar"
}
}
main.tf
module "x1" {
source = "../"
parameter = "${local.map1["name1"]}"
}
module "x2" {
source = "../"
parameter = "${local.map1["name2"]}"
}
This works but it's repetitive/DRY to hardcode the key name.
Ideally I want to able to do something like this:
module "x1" {
source = "../"
parameter = "${local.map1[$var.select]}"
}
Where I can dynamically alter the key variable in the same file. I thought about using null_data_source:
data "null_data_source" "test" {
inputs = {
current = "${var.selector}"
}
}
parameter = "${local.map1[data.null_data_source.test.outputs["current"]]}"
But don't think I will able to inject different variable to selector value since I can't use locals within module block.
Is it possible to dynamically select map variable, e.g?
Currently I am doing this:
vars.tf
main.tf
This works but it's repetitive/DRY to hardcode the key name.
Ideally I want to able to do something like this:
Where I can dynamically alter the key variable in the same file. I thought about using null_data_source:
But don't think I will able to inject different variable to selector value since I can't use locals within module block.