How to unite data from lists?

Hello

I have next variables and need to get role_ids where should be all role.id where

role.label == user.role_labels

like this: role_ides = [ 1111, 3333 ]

  cloud_config = {
    "role" = [
      {
        id             = 1111
        label          = "tf_role1"
        permission_ids = [60, 63, 69, 74, 235]
      },
      {
        id             = 2222
        label          = "tf_role2"
        permission_ids = [60, 63, 69, 74, 235]
      },
      {
        id             = 3333
        label          = "tf_role3"
        permission_ids = [60, 63, 69, 74, 235]
      }
    ]

    "user" = [
      {
        role_labels      = [
          "tf_role1",
          "tf_role3",
        ]
        user_group_label = "tf_uz"
        bucket_label     = "tf_bucket"
      }
    ]
  }

  role_ids = ???
}```

Any idea? Because I’m stuck with this…

Hi @skydion,
I’m not sure if your cloud_config structure might get additional users but the basic idea could be this (for a single user object) - I’m wondering if you wouldn’t need additional keys for additional users:

output "test_role_ids" { value = flatten([for i in local.cloud_config.user.0.role_labels : [for r in local.cloud_config.role : r.id if r.label == i ] ])}

A development basis for more user objects could be:

output "test_role_ids_users" { value = flatten([for u in local.cloud_config.user : [for i in u.role_labels : [for r in local.cloud_config.role : r.id if r.label == i ] ] ] ) }

for additional users


output "test_role_ids_Nusers" { value = [for u in local.cloud_config.user : flatten([for i in u.role_labels : [for r in local.cloud_config.role : r.id if r.label == i ] ]) ] }

Thanks tbugfinder, it’s work!