anu
anu

Reputation: 41

Terraform - Dict with values as list convert to string

dataset_bindings = {
    "infra":[
      "group:[email protected]",
    ],
    "finance":[
      "group:[email protected]",
    ],
    "marketing": [
       "group:[email protected]"
    ]
   }

How can I get all the emails as string. I need to loop thru the dict and get the values and convert those values to string.

Upvotes: 0

Views: 1546

Answers (1)

Marcin
Marcin

Reputation: 238209

You can do this with values and flatten:

locals {
   dataset_bindings = {
    "infra":[
      "group:[email protected]",
    ],
    "finance":[
      "group:[email protected]",
    ],
    "marketing": [
       "group:[email protected]"
    ]
   }
   
   list_of_emails = flatten(values(local.dataset_bindings))        
}

results in:

list_of_emails = [
  "group:[email protected]",
  "group:[email protected]",
  "group:[email protected]",
]

Upvotes: 1

Related Questions