made alert creation optional

This commit is contained in:
Maurizio Noseda Pedraglio 2022-09-30 09:55:38 +02:00
parent 5e2763835f
commit 8b7bf698d2
2 changed files with 34 additions and 26 deletions

View File

@ -106,34 +106,36 @@ resource "google_project_iam_member" "quota_viewer" {
member = module.cf.service_account_iam_email
}
resource "google_monitoring_alert_policy" "alert_policy" {
project = module.project.project_id
display_name = "Quota monitor"
combiner = "OR"
conditions {
display_name = "simple quota threshold for cpus utilization"
condition_threshold {
filter = "metric.type=\"custom.googleapis.com/quota/cpus_utilization\" resource.type=\"global\""
threshold_value = 0.75
comparison = "COMPARISON_GT"
duration = "0s"
aggregations {
alignment_period = "60s"
group_by_fields = []
per_series_aligner = "ALIGN_MEAN"
}
trigger {
count = 1
percent = 0
var.create_alert ? {
resource "google_monitoring_alert_policy" "alert_policy" {
project = module.project.project_id
display_name = "Quota monitor"
combiner = "OR"
conditions {
display_name = "simple quota threshold for cpus utilization"
condition_threshold {
filter = "metric.type=\"custom.googleapis.com/quota/cpus_utilization\" resource.type=\"global\""
threshold_value = 0.75
comparison = "COMPARISON_GT"
duration = "0s"
aggregations {
alignment_period = "60s"
group_by_fields = []
per_series_aligner = "ALIGN_MEAN"
}
trigger {
count = 1
percent = 0
}
}
}
}
enabled = false
user_labels = {
name = var.name
}
documentation {
content = "GCE cpus quota over threshold."
enabled = false
user_labels = {
name = var.name
}
documentation {
content = "GCE cpus quota over threshold."
}
}
}

View File

@ -20,6 +20,12 @@ variable "bundle_path" {
default = "./bundle.zip"
}
variable "create_alert" {
description = "Enables the creation of a sample monitoring alert, false by default."
type = bool
default = false
}
variable "name" {
description = "Arbitrary string used to name created resources."
type = string