I have a for
expression that mostly does what I like:
output "string_ids" {
value = { for client in ["client_a", "client_b"] : client => module.string_client_a[0].id }
}
As you can see, I’ve hard-coded “client_a” into the result of the for loop’s object (as well as the list). So of course, the result isn’t perfect:
string_ids = {
client_a = "i-exampleEc2Id"
client_b = "i-exampleEc2Id"
}
I have read in types and values that terraform supports bracket notation in place of dot notation in order to escape similar kind of variables, so I tried that.
value = { for client in ["string_client_a", "string_client_b"] : client => module["client"][0].id }
I moved my string to the list for testing (so that the module path should resolve). However, I get an error when I try this:
The "module" object does not support this operation.
I think there’s something different about the example use-case for this notation, but there’s something I am not understanding here. It would be helpful if the error could report the kind of operation that the compiler is interpreting.
In cases where a map might contain arbitrary user-specified keys, we recommend using only the square-bracket index notation (
local.map["keyname"]
).
Anyone have an idea that can help me to escape the for loop variable/key inside a module path?
Or really, if there’s a better way to create outputs/data/etc. that represents my child module ID’s mapped to the client name, that’s ultimately what I’m trying to solve; in a dynamic/scalable map of course (1 output, or other resource, call creates map where values are child module output values). I’ve tried googling that but haven’t found any interesting examples.