Skip to content

Commit

Permalink
Simplify filter string
Browse files Browse the repository at this point in the history
  • Loading branch information
romanini-ciandt committed Nov 8, 2024
1 parent 1b19ca7 commit 3cb7cfc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions examples/monitoring_alerts/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ terraform {
backend "local" {}
}

locals {
all_keys_filter = "protoPayload.request.@type=\"type.googleapis.com/google.cloud.kms.v1.DestroyCryptoKeyVersionRequest\""
single_key_filter = "${local.all_keys_filter} AND protoPayload.request.name=~\"${values(module.kms.keys)[0]}/.*\""
}

resource "random_string" "suffix" {
length = 4
special = false
Expand Down Expand Up @@ -50,10 +55,7 @@ resource "google_monitoring_alert_policy" "main" {
conditions {
display_name = "Destroy condition"
condition_matched_log {
filter = join(" AND ", flatten([
"protoPayload.request.@type=\"type.googleapis.com/google.cloud.kms.v1.DestroyCryptoKeyVersionRequest\"",
var.monitor_all_keys_in_the_project ? [] : ["protoPayload.request.name=~\"${values(module.kms.keys)[0]}/.*\""]
]))
filter = var.monitor_all_keys_in_the_project ? local.all_keys_filter : local.single_key_filter
}
}

Expand Down

0 comments on commit 3cb7cfc

Please sign in to comment.