I'm trying to convert a list of items into a map. The element contains a key named tags that contains multiple tags separated by ','
The key should match all nodes that contains the tag.
variable "list" {
type = list(map(string))
default = [
{ a : "a", tags : "k1" },
{ a : "b", tags : "k1" },
{ a : "c", tags : "k1,k2" },
{ a : "d", tags : "k2" },
{ a : "e", tags : "k2" }
]
}
// Output wanted
// {
// "k1" : [{a: a}, {a: b}, {a: c}],
// "k2" : [{a: d}, {a: e}, {a: c}]
// }
I've tried:
[for n in var.list: {for t in split(",", n["tags"]): t => n}]
[
{
"k1" = {a: a}
},
{
"k1" = {a: b}
},
{
"k1" = {a: c},
"k2" = {a: c}
},
{
"k2" = {a: d}
},
{
"k2" = {a: e}
},
]
But I don't know how to merge it after that.