Combining local variables with for_each

Hi @amcsi,

The for_each argument is used in resources in order to create multiple instances of that resource, but locals is not a block which can be repeated in that manner, and has no for_each argument.

What you are looking for are for expressions. While you cannot create multiple locals from a single expressions, you can for example create a list of maps assigned to a single local value with the structure in your example like so:

locals {
  hey = [for f in fileset("${path.module}/functions", "*.js") :
    {
      value          = f
      something_else = "additional: ${f}"
    }
  ]
}
1 Like