Pass list variable to JSON template in terraform

Viewed 6091

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
}
1 Answers
Related