Hi all, any help would be appreciated.
First thing I’d like to know is with HCL and expressions is it possible to massage data from one data structure to another? Well, obviously it is because I’ve done it here but It always seems quite cumbersome compared to a fully featured language, some times including multiple wrangling steps. Maybe this is because the intentions of the expressions or terraform itsself is being stretched. It seems like the target state of my desired data structure is always just out of reach.
I have an ugly but necessary data structure like this
[
{
"a": {
"prop1": 1,
"prop2": 2,
"prop3": 3
}
"b": {
"prop1": 1,
"prop2": 2,
"prop3": 3
}
},
{
"c": {
"prop1": 1,
"prop2": 2,
"prop3": 3
}
"d": {
"prop1": 1,
"prop2": 2,
"prop3": 3
}
},
]
an unfortunate consequence of dynamically building the strucutre and using it with several modules. I need to pass these data to a module using a for_each
for each set of property blob. The the actual names for a b c and d are arbitrary and really the properties are what’s important.
What I need is this:
{
"a": {
"prop1": 1,
"prop2": 2,
"prop3": 3
}
"b": {
"prop1": 1,
"prop2": 2,
"prop3": 3
}
"c": {
"prop1": 1,
"prop2": 2,
"prop3": 3
}
"d": {
"prop1": 1,
"prop2": 2,
"prop3": 3
}
}
I’ve tried quite a few ways of doing it each scarier than the last . In terms of taking work back to my team or documenting loops and data structures I struggle with how the language wants me to use it vs what I want it to do.
toset(flatten([for assignment in local.managed_identity_policy_assignment_roles: [ for properties in assignment: properties ] ] ) )
This got me
{
{
"prop1": 1,
"prop2": 2,
"prop3": 3
},
{
"prop1": 1,
"prop2": 2,
"prop3": 3
}
... etc
}
But a module doesn’t take a set of objects, it needs the map. Is there something glaringly obvious I’m missing here apart from my own desire to use hcl like python!