Howdy, I have some working code after messing around a bit, but I’m looking for feedback on it. I usually avoid these more complex things in the spirit of KISS, but this one would result in a lot of cp/paste.
locals {
owners = flatten([
# This will iterate over the key and flatten the values into a single list of maps.
for identity_group_key, group in local.identity_groups : [
for user in group.owners : {
group = identity_group_key
owner = user
}
]
])
identity_groups = {
"my-group" = {
description = "value"
display_name = "value"
managers = [ "managers" ]
members = [ "members" ]
owners = [ "brett", "frank" ]
}
}
}
# Iterate over local.owners to create a map of maps for the owners
output "identity_groups_owners" {
value = { for user in local.owners : "${user.group}.${user.owner}" => user }
}
# Testing local
output "owners" {
value = local.owners
}
I’m basically wondering if there is an easier way of doing this and if my code comments align with what is actually happening. I was trying to write more detailed code comments, but I’m struggling a bit.