I'm trying to pass a terraform variable to templatefile like the following:
templatefile("${path.module}/functions/nodejs/node_modules/up.js", {
canary_url = var.canary_url
})
where the up.js file looks like:
const urls = ['http://${canary_url}'];
I want to pass the value of canary_url variable which is a url looks like "xxxxx.com", I don't want to escape it, so $${canary_url} is not what I'm looking for. however, when I try to use $${canary_url} or ${canary_url} I get the same error:
Call to function "templatefile" failed: ../../modules/cloudwatch/functions/nodejs/node_modules/up.js:81,87-88: Extra characters after interpolation
│ expression; Expected a closing brace to end the interpolation expression, but found extra characters.
│
│ This can happen when you include interpolation syntax for another language, such as shell scripting, but forget to escape the interpolation start token. If
│ this is an embedded sequence for another language, escape it by starting with "$${" instead of just "${"..
This works fine:
$ cat up.js
const urls = ['http://${canary_url}'];
$ terraform console
> templatefile("${path.module}/up.js", { canary_url = "foo" })
<<EOT
const urls = ['http://foo'];
EOT