iterate over map of filename=>content with for_each in resource

184 Views Asked by At

I want to use a for_each in a kubernetes provider's kubernetes_config_map_v1's data section .. iterating over a map of filename=>content. I do not know how, as this does not work:

...
  files = {for filename in fileset(path.root, "test/*json"): filename => templatefile("${path.root}/${filename}", {
      prefix = local.prefix
    }
  )}
...

resource kubernetes_config_map_v1  xyz {
...
  data = {
    for_each = var.files
    each.key = each.value
  }
}

Error is: The "each" object can be used only in "module" or "resource" blocks, and only when the "for_each" argument is set

Any ideas?

1

There are 1 best solutions below

0
On

The solution is simple, and does not need for_each:

resource kubernetes_config_map_v1  xyz {
...
  data = var.files
}