如何在 JSON 文件中添加地形变量
How add terraform variables in a JSON file
嘿团队我在文档中找不到关于如何在 JSON 文件中添加 terraform 变量的问题,
我需要在这个 JSON,
中注入这个变量
在这个 JSON 这种形状中但不起作用,
我确实尝试过使用 var 和 locals,我尝试使用 var 和 locals,但它不起作用,它是默认的
您可以使用 templatefile
函数 [1]:
locals {
mystring = "Test"
}
resource "grafana_dashboard" "metrics" {
config_json = templatefile("${path.root}/EC2.json.tpl", {
mystring = local.mystring
})
}
为此,您必须将 JSON 更改为:
"datasource": {
"type": "CloudWatch"
"uid": "${mystring}"
}
包含 JSON 数据的文件也应重命名为 EC2.json.tpl
。
[1] https://www.terraform.io/language/functions/templatefile
嘿团队我在文档中找不到关于如何在 JSON 文件中添加 terraform 变量的问题,
我需要在这个 JSON,
中注入这个变量在这个 JSON 这种形状中但不起作用,
我确实尝试过使用 var 和 locals,我尝试使用 var 和 locals,但它不起作用,它是默认的
您可以使用 templatefile
函数 [1]:
locals {
mystring = "Test"
}
resource "grafana_dashboard" "metrics" {
config_json = templatefile("${path.root}/EC2.json.tpl", {
mystring = local.mystring
})
}
为此,您必须将 JSON 更改为:
"datasource": {
"type": "CloudWatch"
"uid": "${mystring}"
}
包含 JSON 数据的文件也应重命名为 EC2.json.tpl
。
[1] https://www.terraform.io/language/functions/templatefile