関数を使う方法とdata sourceを使う方法があります
まず、Jsonの中では ${hoge}
の形式で指定しておきます
例えば
{
"region": "${region}"
}
関数を使う方法
templatefile(path, vars)
Jsonを読み取るときに file
の代わりに templatefile
を使用します
= templatefile("path/to/foo.json", { hoge = var.fuga })
data source を使う方法
参考: template_file
data "template_file" "bar" {
template = file("path/to/foo.json")
vars = {
hoge = var.fuga
}
}
その上で、Jsonを指定する箇所で
= data.template_file.bar.rendered
と指定します
どっちを使うべき?
In Terraform 0.12 and later, the templatefile function offers a built-in mechanism for rendering a template from a file. Use that function instead, unless you are using Terraform 0.11 or earlier.
とあるので、一つ目の関数を使いましょう