Map transformation

updated to be more accurate
Hi Folks,
I have been banging my head for a few days trying to do this. I know I have probably seen it before but google is failing me.
I have created a local from a data source.:

locals {
    my_new_map = [for group in data.okta_groups.aws_groups.groups: {
        id = group.id 
        name = group.name
    } if contains(local.groups_not_to_check, group.name) == false] 
}

the result is

{
  id = <group1id>
  name = <group1name>
}
{
  id = <group2id>
  name = <group2name>
}
{
  ...
}

What i need is to transform it to this:

[
  <group1name> = <group1id>
  <group2name> = <group2id>
  ...
]

groupnames and ids are all unique so can be used as keys

Don’t know if it is possible in my for statement or not but am willing to create a local to do it.
Any help would be awesome.

It’s not 100% what you wanted I’m still working on converting it to an array but I was able to map name = id as an object map

locals {
  my_new_map = merge([
    for group in [
      {
        id   = 1
        name = "name1"
      },
      {
        id   = 2
        name = "name2"
      },
      {
        id   = 3
        name = "name3"
      },
    ] :
    {
      (group.name) = group.id
    } if contains(["name3"], group.name) == false
    ]...
  )
}

output "map" {
  value = local.my_new_map
}

Output value would be

Changes to Outputs:
  + map = {
      + name1 = 1
      + name2 = 2
    }

You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.

If I figure out the array Ill update this post, but you may be able to get this to work for you as well it’s a start anyway.