# Create a monitoring dashboard for the provisioned Cloud Run service.
#
# The dashboard, defined in ./dashboard.json, contains:
# - Request counts broken down by response code class (ignoring 404s).
# - Request latencies for 50th, 95th and 99th percentile.
# - Container CPU and memory utilisations for 50th, 95th and 99th percentile.
# - Container instance count and billable instance time.
locals {
  dashboard_template = templatefile("${path.module}/dashboard.json", {
    service_name = var.name
    region       = var.cloud_run_region
  })
}

resource "google_monitoring_dashboard" "dashboard" {
  count = var.create_monitoring_dashboard ? 1 : 0

  dashboard_json = local.dashboard_template
}