[英]Pass list variable to JSON template in terraform
I am trying to create a cloudwatch dashboard in terraform that would be configurable via variables.我正在尝试在 terraform 中创建一个可以通过变量配置的 cloudwatch 仪表板。 I realize that dashboard body is a JSON string, so basic interpolation (like "region" property below) works.
我意识到仪表板主体是一个 JSON 字符串,因此基本插值(如下面的“区域”属性)可以工作。 But with something like "metrics" I need to pass a list - and terraform throws "invalid interpolation" error.
但是对于“指标”之类的东西,我需要传递一个列表 - 并且 terraform 会引发“无效插值”错误。 Is there a way to have configurable template where I can pass complex variables?
有没有办法让我可以在其中传递复杂变量的可配置模板?
resource "aws_cloudwatch_dashboard" "dashboard" {
dashboard_name = "dashboard"
dashboard_body = <<EOF
{
"widgets": [
{
"type": "metric",
"width": 12,
"properties": {
"metrics": ${local.database_metrics},
"region": "${var.aws_region}"
}
}
]
}
EOF
}
Terraform 有一个jsonencode 功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.