How to get the value from map(list(map)) vairable

I am trying to assign multiple group with different permission in the vault namespace but not able to extract the value. Can someone help ??


eam_namespace = {
  namespace-team1 = [
    {
      group_name  = "Engineeringr"
      team_policy = "namespace-del.hcl"
    },
    {
      group_name  = "Contractor"
      team_policy = "namespace-eng.hcl"
    }
  ],
  namespace-team2 = [
    {
      group_name  = "Engineering"
      team_policy = "namespace-del.hcl"
    },
    {
      group_name  = "Contractor"
      team_policy = "namespace-eng.hcl"
    }
  ]
}

module "vault_namespace" {
  for_each = var.team_namespace
  source   = "./../../modules/vault_onboarding/vault_namespace"
  path     = each.key
}

locals {
  team_namespace = flatten([
  for group_name, team_name in var.team_namespace : [
      {
        group_name = group_name
        team_name = team_name
      }
      ]
  ])
}

module "vault_policies" {
  for_each       = { for team_name_id in local.team_namespace : team_name_id.team_name => team_name_id }
  source         = "./../../modules/vault_onboarding/vault-policies"
  team_name      = each.value.team_name
  team_namespace = each.value.team_name
  team_policy    = "../policies/namespace-admin.hcl"
  depends_on     = [module.vault_namespace]
}

getting below error


│ Error: Invalid object key
│
│   on main.tf line 54, in module "vault_pol
icies":
│   54:   for_each       = { for team_name_i
d in local.team_namespace : team_name_id.tea
m_name => team_name_id }
│     ├────────────────
│     │ team_name_id.team_name is tuple with
 2 elements
│
│ The key expression produced an
│ invalid result: string required.
╵

I tried to flatten function but no success .. Need help