Hi,
From a data source I get a list of ids. For each of these, I need to call a module with the id as input1 and several other settings. Something like this.
module "a" {
for_each = toset(local.ids)
source = "./modules/a"
id = each.key
setting1 = ...
setting2 = ...
...
}
But, I need to have a map with custom settings
locals {
custom_settings = {
"id1" = {
"setting1" : "..."
"setting2" : "..."
}
"id3" = {
"setting2" : "..."
}
}
}
If a custom setting exists for the id, I should use it in the module call, otherwise a settings default.
For the case of no setting, I was planning to pass in null and have the module input variable be non-nullable so it gets the default.
variable "setting1" {
nullable = false
default = "default"
}
But I cannot figure out how to look for the nested value. What approach could I use? I was trying to use a for loop
value = [ for application in local.applications : {
query = lookup(local.custom_settings, application, null) == null ? null : lookup(local.custom_settings.application, "setting1", null)
}
]
But it fails, I don’t see this syntax with [ ] in the for loop documentation at all so I don’t know what the iterating variable really is.
Maybe the premise with the customizations map seems strange, but unfortunately, I cannot change it.