google-cloud-platformterraformmonitoringmetricsalerts

GCP terraform - alerts module based on log metrics


As per subject, I have set up log based metrics for a platform in gcp i.e. firewall, audit, route etc. monitoring.

enter image description here

Now I need to setup alert policies tied to these log based metrics, which is easy enough to do manually in gcp.

enter image description here

However, I need to do it via terraform thus using this module:

https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_alert_policy#nested_alert_strategy

I might be missing something very simple but finding it hard to understand this as the alert strategy is apparently required but yet does not seem to be supported?

I am also a bit confused on which kind of condition I should be using to match my already setup log based metric?

This is my module so far, PS. I have tried using the same filter as I did for setting up the log based metric as well as the name of the log based filter:

    resource "google_monitoring_alert_policy" "alert_policy" {
  display_name = var.display_name
  combiner     = "OR"
  conditions {
    display_name = var.display_name
    condition_matched_log {
        filter = var.filter
        #duration   = "600s"
        #comparison = "COMPARISON_GT"
        #threshold_value = 1
      }
    }

  user_labels = {
    foo = "bar"
  }
}

var filter is:

resource.type="gce_route" AND (protoPayload.methodName:"compute.routes.delete" OR protoPayload.methodName:"compute.routes.insert")


Solution

  • Got this resolved in the end.

    Turns out common issue:

    https://issuetracker.google.com/issues/143436657?pli=1

    Had to add this to the filter parameter in my terraform module after the metric name - AND resource.type="global"