Here is my issue - I have a locals code block like the below. I need to create a Map from these values (these values are used in multiple places)
locals {
object = {
1 = {
name = "val1"
keys = ["val1"]
}
2 = {
name = "val2"
keys = ["val2", "val3", "val4"]
}
}
associations = flatten(
[
for obj in local.object : [
for association_key in obj.keys : {
"${obj.name}-${association_key}" = {
key = obj.name
association_key = association_key
}
}
]
]
)
}
Which when I run a terraform plan outputting the above - I get:
testing = [
+ {
+ val1-val1 = {
+ association_key = "val1"
+ key = "val1"
}
},
+ {
+ val2-val2 = {
+ association_key = "val2"
+ key = "val2"
}
},
+ {
+ val2-val3 = {
+ association_key = "val3"
+ key = "val2"
}
},
+ {
+ val2-val4 = {
+ association_key = "val4"
+ key = "val2"
}
},
]
What I need to get however looks like this:
testing = [
+ val1-val1 = {
+ association_key = "val1"
+ key = "val1"
}
+ val2-val2 = {
+ association_key = "val2"
+ key = "val2"
}
+ val2-val3 = {
+ association_key = "val3"
+ key = "val2"
}
+ val2-val4 = {
+ association_key = "val4"
+ key = "val2"
}
]
The reason for this is that there are many repetitions in keys value from object and there needs to be a unique value in the map.
I have attempted the solution Here - but I have not been able to create the Map that I need.