嘿團隊我在檔案中找不到關于如何在 JSON 檔案中添加 terraform 變數的問題,
我需要在這個 JSON 中注入這個變數,

在這種形狀的 JSON 中,但它不起作用,

我確實嘗試了 var 和 locals,我嘗試了 var 和 locals,但它不起作用,默認情況下
uj5u.com熱心網友回復:
您可以使用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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/452079.html
上一篇:決議JSONAPI回應
