I am trying to inject bunch of files into template_file using for_each . but I am getting exception. Main reason to go with this approach is to update the json files dynamically with the var.
resource "datadog_monitor_json" "monitor_json" {
monitor = data.template_file.resource-message.rendered
}
data "template_file" "resource-message" {
for_each = local.json_file
template = file(each.key)
vars = {
test = xyz
}
}
locals {
json_file = fileset("path.module","folder/*.tpl")
}
error response
Because data.template_file.resource-message has “for_each” set, its attributes must be accessed
│ on specific instances.
│
│ For example, to correlate with indices of a referring resource, use:
│ data.template_file.resource-message[each.key]