diff --git a/blueprints/cloud-operations/quota-monitoring/README.md b/blueprints/cloud-operations/quota-monitoring/README.md index c80a7756..fcfad1e7 100644 --- a/blueprints/cloud-operations/quota-monitoring/README.md +++ b/blueprints/cloud-operations/quota-monitoring/README.md @@ -28,7 +28,7 @@ Labels are set with project id (which may differ from the monitoring workspace p GCP Metrics Explorer, usage, limit and utilization view sample -The solution also creates a basic monitoring alert policy, to demonstrate how to raise alerts when quotas utilization goes over a predefined threshold. +The solution can also create a basic monitoring alert policy, to demonstrate how to raise alerts when quotas utilization goes over a predefined threshold, to enable it, set variable `alert_create` to true and reapply main.tf after main.py has run at least one and quota monitoring metrics have been creaed. ## Running the blueprint diff --git a/blueprints/cloud-operations/quota-monitoring/main.tf b/blueprints/cloud-operations/quota-monitoring/main.tf index 0593f4fd..674482c8 100644 --- a/blueprints/cloud-operations/quota-monitoring/main.tf +++ b/blueprints/cloud-operations/quota-monitoring/main.tf @@ -106,39 +106,40 @@ resource "google_project_iam_member" "quota_viewer" { member = module.cf.service_account_iam_email } -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 - } + +resource "google_monitoring_alert_policy" "alert_policy" { + count = var.alert_create ? 1 : 0 + 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." } } + resource "random_pet" "random" { length = 1 } diff --git a/blueprints/cloud-operations/quota-monitoring/variables.tf b/blueprints/cloud-operations/quota-monitoring/variables.tf index cce24ca4..53ca0f63 100644 --- a/blueprints/cloud-operations/quota-monitoring/variables.tf +++ b/blueprints/cloud-operations/quota-monitoring/variables.tf @@ -14,18 +14,18 @@ * limitations under the License. */ +variable "alert_create" { + description = "Enables the creation of a sample monitoring alert, false by default." + type = bool + default = false +} + variable "bundle_path" { description = "Path used to write the intermediate Cloud Function code bundle." type = string 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 @@ -33,7 +33,7 @@ variable "name" { } variable "project_create" { - description = "Create project instead ofusing an existing one." + description = "Create project instead of using an existing one." type = bool default = false }