I am trying to create a cloudwatch dashboard in terraform that would be configurable via variables. I realize that dashboard body is a JSON string, so basic interpolation (like "region" property below) works. But with something like "metrics" I need to pass a list - and terraform throws "invalid interpolation" error. 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 has a jsonencode function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With