Не удалось добавить несколько условий в google_monitoring_alert_policy для политики предупреждений GCP с использованием Terraform.

Пожалуйста, дайте мне знать, как указать более одного условия в политике предупреждений GCP через Terraform. Я попробовал несколько способов создания списка условий, как указано в документации, но ничего не сработало.

Ниже приведен фрагмент кода:

resource "google_monitoring_alert_policy" "alert_policy" {
  display_name = "Request count Policy"
  combiner     = "OR"
  conditions   = [
    display_name = "Request count condition"
    condition_threshold  {
      filter          = "metric.type=\"run.googleapis.com/request_count\" AND resource.type=\"cloud_run_revision\" AND metric.label.response_code_class=\"4xx\" AND resource.label.service_name=\"dev-ms\""
      duration        = "60s"
      comparison      = "COMPARISON_GT"
      threshold_value = 5
      trigger = {
        count = 1
      }
      aggregations  {
        alignment_period     = "60s"
        per_series_aligner   = "ALIGN_DELTA"
        cross_series_reducer = "REDUCE_SUM"
        group_by_fields      = ["metric.label.response_code_class", "resource.label.revision_name"]
      }
    },
    display_name = "Request latencies condition"
    condition_threshold {
      filter          = "metric.type=\"run.googleapis.com/request_count\" AND resource.type=\"cloud_run_revision\" AND metric.label.response_code_class=\"4xx\" AND resource.label.service_name=\"dev-ms\""
      duration        = "60s"
      comparison      = "COMPARISON_GT"
      threshold_value = 5
      trigger = {
        count = 1
      }
      aggregations  {
        alignment_period     = "60s"
        per_series_aligner   = "ALIGN_DELTA"
        cross_series_reducer = "REDUCE_SUM"
        group_by_fields      = ["metric.label.response_code_class", "resource.label.revision_name"]
      }
    }
]
  documentation {
    content = "The cloud run based request count alerting policy."
  }
  notification_channels = [
    google_monitoring_notification_channel.email0.id
  ]

  user_labels = {
    name = "offer-engine-alert-policy"
  }
}

Покажите проделанную работу и сообщения об ошибках и/или сведения о проблеме.

John Hanley 19.12.2020 07:31

Привет, Джон. Кажется, возникла проблема с синтаксисом, которую я не могу решить. Я создал список условий, но применение TF приводит к ошибке с выделением «Блок условий здесь не ожидается *» или «Отсутствует разделитель значений ключа» и «Использовать новую строку в качестве разделителя блоков».

Surabhi Sharma 19.12.2020 08:32
Создание приборной панели для анализа данных на GCP - часть I
Создание приборной панели для анализа данных на GCP - часть I
Недавно я столкнулся с интересной бизнес-задачей - визуализацией сбоев в цепочке поставок лекарств, которую могут просматривать врачи и...
1
2
2 530
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 1

Ответ принят как подходящий

Приведенный ниже синтаксис работал для меня. Вместо объявления списка с помощью [] я повторил блок условий, и это сработало!!

resource "google_monitoring_alert_policy" "alert_policy" {
  display_name = "Request count Policy"
  combiner     = "OR"
  conditions   {
    display_name = "Request count condition"
    condition_threshold  {
      filter          = "metric.type=\"run.googleapis.com/request_count\" AND resource.type=\"cloud_run_revision\" AND metric.label.response_code_class=\"4xx\" AND resource.label.service_name=\"dev-ms\""
      duration        = "60s"
      comparison      = "COMPARISON_GT"
      threshold_value = 5
      trigger {
        count = 1
      }
      aggregations  {
        alignment_period     = "60s"
        per_series_aligner   = "ALIGN_DELTA"
        cross_series_reducer = "REDUCE_SUM"
        group_by_fields      = ["metric.label.response_code_class", "resource.label.revision_name"]
      }
    }
  }
  conditions   {
    display_name = "Request latencies condition"
    condition_threshold {
      filter          = "metric.type=\"run.googleapis.com/request_count\" AND resource.type=\"cloud_run_revision\" AND metric.label.response_code_class=\"4xx\" AND resource.label.service_name=\"dev-ms\""
      duration        = "60s"
      comparison      = "COMPARISON_GT"
      threshold_value = 5
      trigger  {
        count = 1
      }
      aggregations  {
        alignment_period     = "60s"
        per_series_aligner   = "ALIGN_DELTA"
        cross_series_reducer = "REDUCE_SUM"
        group_by_fields      = ["metric.label.response_code_class", "resource.label.revision_name"]
      }
    }
}
  documentation {
    content = "The cloud run based request count alerting policy."
  }
  notification_channels = [
    google_monitoring_notification_channel.email0.id
  ]

  user_labels = {
    name = "alert-policy"
  }
}

Другие вопросы по теме