Reputation: 1426
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?
Upvotes: 8
Views: 5884
Reputation: 1855
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}"}
}
Upvotes: 16