terraform nested loops for storing values

Viewed 136

I have below two list variables

env = ["dev", "qa"]

stage = ["stage1", "stage2", "stage3", "stage4", "stage5"]

My requirement is that i want to store the values, in such a way like "api-dev-stage1" "dev-stage2" etc.

display_name        = "api-$var.stage-var.$env"

I am not sure how to write nested loops. Please help

1 Answers

You don't need nested loop. setproduct is enough:

locals {
  display_name_list = [for val in setproduct(var.env, var.stage): "api-${val[0]}-${val[1]}"]                        
}
Related