Using google_monitoring_dashboard with templates

183 views
Skip to first unread message

Rob Clark

unread,
Aug 4, 2020, 5:25:05 PM8/4/20
to Terraform
Hey All, has anyone tried to use the data template_file with google_monitoring_dashboard resource?

Here is what I am trying to do.

Basically we want to create a dashboard template for our pubsub subscriptions, this template would take 1 or many subs (It's up to the user to pass to the module). 

Here is my header template.
 "displayName": "${dash_name}",
  "gridLayout": {
    "columns": "2",
    "widgets": [
      ${chart_output}
    ]
    }
}

Basic chart template.
        "title": "Unread Messages",
        "xyChart": {
          "chartOptions": {
            "mode": "COLOR"
          },
          "dataSets": [
            {
              "minAlignmentPeriod": "60s",
              "plotType": "LINE",
              "timeSeriesQuery": {
                "timeSeriesFilter": {
                  "aggregation": {
                    "crossSeriesReducer": "REDUCE_SUM",
                    "groupByFields": [
                      "resource.label.\"subscription_id\""
                    ],
                    "perSeriesAligner": "ALIGN_SUM"
                  },
                  "filter": "metric.type=\"pubsub.googleapis.com/subscription/num_undelivered_messages\" resource.type=\"pubsub_subscription\" resource.label.\"subscription_id\"=\"${sub_name}\""
                },
                "unitOverride": "1"
              }
            }
          ],
          "timeshiftDuration": "0s",
          "yAxis": {
            "label": "y1Axis",
            "scale": "LINEAR"
          }
        }

Code:
resource "google_monitoring_dashboard" "pubsub-overview" {
dashboard_json = data.template_file.header_chart.rendered
}

data template_file "header_chart" {
template = "{${file("${path.module}/templates/header.tmpl")}"

vars = {
dash_name = var.dash_name
chart_output = jsonencode(join("\n" ,data.template_file.pubsub_chart.*.rendered))
}
}

data template_file "pubsub_chart" {
template = "{${file("${path.module}/templates/charts2.tmpl")}"
vars = {
sub_name = "${var.sub_name}"
}
}

Here is the error I am getting:
google_monitoring_dashboard.pubsub-overview: Creating...

Error: Error creating Dashboard: googleapi: Error 400: Invalid value at 'dashboard.grid_layout.widgets[0]' (type.googleapis.com/google.monitoring.dashboard.v1.Widget)

Thanks!

Reply all
Reply to author
Forward
0 new messages