Search code examples
google-cloud-platformterraformterraform-provider-gcpgoogle-cloud-monitoring

Terraform Unsupported block type error for "condition_monitoring_query_language"


I am trying to deploy an alert policy in terraform but came across an error saying that this block is unsupported. I find this confusing because I have used another field called condition absent and the policy works fine. Here is the link to policy I am trying to create: google_monitoring_alert_policy

 Error: Unsupported block type

  on terraform/modules/google-monitoring-mql-alert-policy/main.tf line 29, in resource "google_monitoring_alert_policy" "default":
  29:       condition_monitoring_query_language  {

Blocks of type "condition_monitoring_query_language" are not expected here.

This is the code so far. it was a simple change from condition_absent to condition_monitoring_query_language

    resource "google_monitoring_alert_policy" "default" {
  depends_on = [
    null_resource.is_ready
  ]

  display_name          = each.key
  project               = var.gcp_project
  enabled               = lookup(each.value, "enabled", true)
  combiner              = lookup(each.value, "combiner", "OR")
  notification_channels = lookup(each.value, "notification_channels", null) == null ? null : matchkeys(values(var.notificationlist), keys(var.notificationlist), lookup(each.value, "notification_channels", []))


  dynamic "conditions" {
    for_each = each.value["conditions"]

    content {
      display_name = conditions.key

      condition_monitoring_query_language  {
        query    = lookup(conditions.value, "query", null)
        duration = lookup(conditions.value, "duration", null)
        dynamic "trigger" {
          for_each = lookup(conditions.value, "trigger", [])
          content {
            count   = lookup(trigger.value, "count", null)
            percent = lookup(trigger.value, "percent", null)
          }
        }
      }
    }
  }

  dynamic "documentation" {
    for_each = lookup(each.value, "documentation", [])
    content {
      content   = lookup(documentation.value, "documentation_content", null)
      mime_type = lookup(documentation.value, "documentation_mime_type", null)
    }
  }

What should I do to successfully run my "terraform plan" ? Thank you in advance


Solution

  • Monitoring Query Language based alerting was added in v3.46.0. The error msg suggests that you are using older version. You have to upgrade your gcp provider.