red888
red888

Reputation: 31560

How to mutate a map's keys and values to change their case

I have this map:

tags = {
  "Name" = "sdfsdfsdf"
  "ZZZZ" = "ABC-DE"
  "sdfsEEEdfsdfE" = "sdfsdfsdQQQf"
}

I want to generate a new map from that one but lower case all the keys and values.

I thought I could do this with for_each inside of locals but looks like that's not supported? I want to create a new map (via locals somehow) for this

This is not valid syntax but I want to do something like this:

locals{
  test = {
    for i in tags:
    lower(i.key) => lower(i.key)
    lower(i.value) => lower(i.value)
  }
}

Upvotes: 2

Views: 1910

Answers (1)

red888
red888

Reputation: 31560

This is super easy, but I had a really hard time finding an example of it for some reason

locals {
  newmap = {
    for key, value in local.tags :
      lower(key) => lower(value)
  }
}

Upvotes: 5

Related Questions