google_monitoring_alert_policy

A description of the conditions under which some aspect of your system is considered to be "unhealthy" and the ways to notify people or services about this state.

To get more information about AlertPolicy, see:

Example Usage - Monitoring Alert Policy Basic

resource "google_monitoring_alert_policy" "alert_policy" {
  display_name = "My Alert Policy"
  combiner     = "OR"
  conditions {
    display_name = "test condition"
    condition_threshold {
      filter     = "metric.type=\"compute.googleapis.com/instance/disk/write_bytes_count\" AND resource.type=\"gce_instance\""
      duration   = "60s"
      comparison = "COMPARISON_GT"
      aggregations {
        alignment_period   = "60s"
        per_series_aligner = "ALIGN_RATE"
      }
    }
  }

  user_labels = {
    foo = "bar"
  }
}

Example Usage - Monitoring Alert Policy Evaluation Missing Data

resource "google_monitoring_alert_policy" "alert_policy" {
  display_name = "My Alert Policy"
  combiner     = "OR"
  conditions {
    display_name = "test condition"
    condition_threshold {
      filter     = "metric.type=\"compute.googleapis.com/instance/disk/write_bytes_count\" AND resource.type=\"gce_instance\""
      duration   = "60s"
      comparison = "COMPARISON_GT"
      aggregations {
        alignment_period   = "60s"
        per_series_aligner = "ALIGN_RATE"
      }
      evaluation_missing_data = "EVALUATION_MISSING_DATA_INACTIVE"
    }
  }

  user_labels = {
    foo = "bar"
  }
}

Example Usage - Monitoring Alert Policy Forecast Options

resource "google_monitoring_alert_policy" "alert_policy" {
  display_name = "My Alert Policy"
  combiner     = "OR"
  conditions {
    display_name = "test condition"
    condition_threshold {
      filter     = "metric.type=\"compute.googleapis.com/instance/disk/write_bytes_count\" AND resource.type=\"gce_instance\""
      duration   = "60s"
      forecast_options {
        forecast_horizon = "3600s"
      }
      comparison = "COMPARISON_GT"
      aggregations {
        alignment_period   = "60s"
        per_series_aligner = "ALIGN_RATE"
      }
    }
  }

  user_labels = {
    foo = "bar"
  }
}

Example Usage - Monitoring Alert Policy Promql Condition

resource "google_monitoring_alert_policy" "alert_policy" {
  display_name = "My Alert Policy"
  combiner     = "OR"
  conditions {
    display_name = "test condition"
    condition_prometheus_query_language {
      query      = "compute_googleapis_com:instance_cpu_usage_time > 0"
      duration   = "60s"
      evaluation_interval = "60s"
      alert_rule  = "AlwaysOn"
      rule_group  = "a test"
    }
  }

  alert_strategy {
    auto_close  = "1800s"
  }
}

Argument Reference

The following arguments are supported:

The conditions block supports:

The condition_absent block supports:

The aggregations block supports:

The trigger block supports:

The condition_monitoring_query_language block supports:

The trigger block supports:

The condition_threshold block supports:

The denominator_aggregations block supports:

The forecast_options block supports:

The trigger block supports:

The aggregations block supports:

The condition_matched_log block supports:

The condition_prometheus_query_language block supports:


The alert_strategy block supports:

The notification_rate_limit block supports:

The notification_channel_strategy block supports:

The documentation block supports:

Attributes Reference

In addition to the arguments listed above, the following computed attributes are exported:

The creation_record block contains:

Timeouts

This resource provides the following Timeouts configuration options:

Import

AlertPolicy can be imported using any of these accepted formats:

In Terraform v1.5.0 and later, use an import block to import AlertPolicy using one of the formats above. For example:

import {
  id = "{{name}}"
  to = google_monitoring_alert_policy.default
}

When using the terraform import command, AlertPolicy can be imported using one of the formats above. For example:

$ terraform import google_monitoring_alert_policy.default {{name}}

User Project Overrides

This resource supports User Project Overrides.