Terraform 仪表板主体内的模板文件
我想知道是否可以在Dashbody资源中使用templatefile。我正在尝试以下方法Terraform 仪表板主体内的模板文件,terraform,amazon-cloudwatch,Terraform,Amazon Cloudwatch,我想知道是否可以在Dashbody资源中使用templatefile。我正在尝试以下方法 dashboard_body = <<EOF { "widgets": [ { "type": "metric", "x": 0, "y": 0, "width": 12, "heigh
dashboard_body = <<EOF
{
"widgets": [
{
"type": "metric",
"x": 0,
"y": 0,
"width": 12,
"height": 6,
"properties": {
"metrics": [
templatefile("${path.module}/backends.tmpl", { instances = aws_instance.web })
],
"period": 300,
"stat": "Average",
"region": "us-east-1",
"title": "EC2 Instance CPU"
}
}
]
}
EOF
但是,当我运行terraform apply时,会收到以下错误消息
错误:“dashboard_body”包含无效的JSON:文本为true的无效字符“e”(应为“r”)
在dashboards.tf第1行的资源“aws_cloudwatch_dashboard”“main”中:
1:资源“aws\U cloudwatch\U仪表板”“主”{
提前感谢您的帮助。是的,您可以使用模板文件。这里似乎有一个小语法错误:
templatefile("${path.module}/backends.tmpl", { instances = aws_instance.web })
应将整个函数包装在插值块中,如下所示:
${templatefile("${path.module}/backends.tmpl", { instances = aws_instance.web })}
${templatefile("${path.module}/backends.tmpl", { instances = aws_instance.web })}