I am looking to replicate templatefile(), but with a different regex than the usual ${...}. The source here is js code, which already uses${...} syntax for other purposes, messing up the terraform templating.
E.g. my input map may be:
variable "values" {
type = map
default = {
"a" = "Was A"
"b" = "Hello world"
}
}
My input is something like:
This is my input with [a] over and [a] over and [b] multiple times [a] and [b],
and I already use ${somevar} and ${anothervar} for something unrelated.
I want to replace every case of [a] with its value in the map, same for [b].
Sort of:
templatefile_alternate("path/to/file", var.values, "[]")
which says, "don't look for ${a} and ${b}, but instead [a] and [b].
I could use replace, but then I end up having to chain one after the other, and getting a loop is difficult:
out = replace(replace(in, "[a]",var.values[a]), "[b]", var.values[b])
If there are more than 1 or 2 items, it is unmanageable.