我正在尝试将 terraform 变量传递给模板文件,如下所示:
templatefile("${path.module}/functions/nodejs/node_modules/up.js", {
canary_url = var.canary_url
})
up.js 文件如下所示:
const urls = ['http://${canary_url}'];
我想传递canary_url变量的值,它是一个看起来像“xxxxx.com”的url,我不想转义它,所以$${canary_url}不是我要找的。但是,当我尝试使用 $${canary_url} 或 ${canary_url} 时,我收到相同的错误:
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 "${"..
这很好用:
$ cat up.js
const urls = ['http://${canary_url}'];
$ terraform console
> templatefile("${path.module}/up.js", { canary_url = "foo" })
<<EOT
const urls = ['http://foo'];
EOT