Hi all,
I can’t quite figure out the for_each
syntax to iterate over a map, and extract embedded lists
to pass to my module, would someone know the syntax for the below?
Variables:
variable "repos" {
type = map(object({
name = set(string)
}))
default = {
springboot = {
name = [
"springboot-a",
"springboot-b",
"springboot-c"
],
push_teams = ["springboot-developers"]
},
node = {
name = [
"node-a",
"node-b",
"node-c"
],
push_teams = ["node-developers" ]
}
}
}
Module:
module "repository" {
for_each = { for k, v in var.repos: ... } # ??
name = each.value.name
push_teams = each.value.push_teams
}
I’m unsure of the syntax to extract/flatten this object to pass to the module above.
I’d expect once the data is unrolled to look something like the below:
repos.springboot.name[0] = "springboot-a"
repos.springboot.push_teams[0] = [ "springboot-developers" ]
repos.springboot.name[1] = "springboot-b"
repos.springboot.push_teams[1] = [ "springboot-developers" ]
repos.springboot.name[2] = "springboot-c"
repos.springboot.push_teams[2] = [ "springboot-developers" ]
repos.node.name[0] = "node-a"
repos.springboot.push_teams[0] = [ "node-developers" ]
repos.node.name[1] = "node-b"
repos.springboot.push_teams[0] = [ "node-developers" ]
repos.node.name[0] = "node-c"
repos.springboot.push_teams[0] = [ "node-developers" ]
Thanks!