I am setting up for IaC in Terraform for Google cloud function when error occurs.
This is my code in Terraform:
resource "google_monitoring_alert_policy" "my_cf_alert_policy" {
display_name = "${var.ENVIRONMENT}_my_cf_error_alert"
notification_channels = [
google_monitoring_notification_channel.email_channel.name
]
combiner = "OR"
conditions {
display_name = "send_alert_when_severity=ERROR"
condition_matched_log {
filter = "resource.type=\"cloud_function\" resource.labels.function_name=\"${google_cloudfunctions_function.my_cf.name}\" severity=\"ERROR\""
}
}
alert_strategy {
auto_close = "604800s"
notification_rate_limit {
period = "300s"
}
}
}
but when I see the same alert policy in GCP console, I could see the Severity is No severity
as attached.
I need to have Severity set to Error
.
You need to add the
severity
field in thegoogle_monitoring_alert_policy
block. This code should work:For log-based metrics, you need to specify the
notification_rate_limit
field.FYI.
notificationChannelStrategy
is not allowed for log-based alerts