Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
461 views
in Technique[技术] by (71.8m points)

functional programming - How to transform a map to map in Terraform

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?

question from:https://stackoverflow.com/questions/65871005/how-to-transform-a-map-to-map-in-terraform

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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}"}
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...