Help with getting values from lists and maps

I am trying to output values for an object which is a combination of a map and list. The output will be a combination of policy’s and all its values.
I was referring to following discussion to figure it out

However, my requirements are a bit different as you can see below:

Variable Object looks like this:

variable iam-policy-users-map {
default = {
# following dataset does not work
    "policy3" = [{ key1 = "value1", key2 = "value2" }, { key1 = "value3", key2 = "value4" }]
    "policy4" = [{ key1 = "value5", key2 = "value6" }, { key1 = "value7", key2 = "value8" }]
    "policy5" = { key1 = "value5", key2 = "value6" }
  }
}

I would like to output all the policies, with its keys and value which is list(map) e:g

policy3_value1_value2
policy3_valu31_value4
policy4_value5_value6
policy4_value7_value8
policy5_value5_value6

Foll is my local definition:

locals {
  user_policy_pairs = flatten([
    for policy, users in var.iam-policy-users-map : [ #list
      for value1, value2 in users : { # map
        policy = policy
        value1   = value1
        value2   = value2
      }
    ]
  ])

Foll is the output I have which does not show the output.

output "association-map" {
  value = {
    for obj in local.user_policy_pairs :
    "${obj.policy}_${obj.value1}_${obj.value2}" => [obj.policy, obj.value1, obj.value2]
  }
}

Instead, I get foll error:

obj.value2 is object with 2 attributes

Eventually, I want to use the object to create dynamic content in following manner:

resource "resourcename" r1{
....
....
dynamic "element"{
   for_each=local.user_policy_pairs
   iterator=next
   }
   content {
       policy = next.value.policy
       value1 = next.value.value1
       value2 = next.value.value2
   }
}
...
...

Can someone help?

I was able to figure this out. Closing this now :slight_smile: