How to transform a map to map in Terraform

Viewed 1549

I have a map in Terraform, values of which I want to transform by prepending them with a string, resulting in another map.

variable "my_map" {
  type = map(string)
}


locals {
  my_new_map = [for key, value in var.my_map: { key = "prefix/${value}"}]
}

But local.my_new_map is a tuple instead of a map. What am I missing for the result to be a map?

1 Answers

You must use the map syntax with { and } :

variable "my_map" {
  type = map(string)
}


locals {
  my_new_map = {for key, value in var.my_map: key => "prefix/${value}"}
}
Related