Terraform Key Value Pairs

I am currently writing a TF module for Vault that manages our namespaces, and am having a bit of trouble trying to extract a YAML dictionary into values.

All of the data will exist in a YAML file, with each namespace providing the following values, which will be used to provision OIDC roles, policy etc.

namespaces:
  "project-bob":
    owner: bob
    ad-group:
    roles:
      - "A"
      - "B"
    horses:
      - "C"
    dogs:
      - "D"
    cats:
      - "E"
      - "F"
      - "G"
    employee: "full-time"
    supporthrs: 247hrs
    edit: true

I can extract the data in terraform console as a complete dump of the data, using yamldecode as well as using hardcoded values for a given namespace to extract elements.

With the key being in this case project-bob and the values being all of the project-bob data.

What I am having trouble with, is extracting the key as a variable, when we won’t know the value of the individual keys.

All of the examples I have found have known key values, which make it easy to then get the values.
I will be open to changing the format of the schema if it would be better, but I need to keep the elements.

if you convert your yamldecode in a for_each expression and iterable with these itens you can use your dynamic values like a “map”. if you need a dynamic usage with these values, i will recommend you create a inner module to call every time you call a element in a for_each.

The argument of the inner module will be the value passed in the map, and a reference of the module will be a namespace “name”.