I would like to know if it is possible to use temporary variables inside a for loop for intermediate computation. If yes, what is the syntax to use that, the example is simplified just to illustrate the problem. This example code works. I've commented the portion which doesn't work, but would like to know how to use intermediate variable. Thanks!
locals {
nestedmap = <<-EOT
user-john:
db: "db34"
tables:
t1:
rows: 4
t2:
rows: 8
user-chris:
db: "db22"
tables:
t1:
rows: 3
t2:
rows: 7
user-mary:
db: "db78"
tables:
t1:
rows: 2
t2:
rows: 10
EOT
flatlist = flatten([
for ux_key, ux_val in yamldecode(local.nestedmap): [
for tx_key, tx_val in ux_val.tables: {
pfx = trimprefix(ux_key, "user-")
#key = "${pfx}-${tx_key}"
key = "${trimprefix(ux_key, "user-")}-${tx_key}"
db = ux_val.db
rows = tx_val.rows
}
]
])
flatmap = {for fx in local.flatlist: fx.key => fx}
}