From c0ca53475296eb76e4fbac274b21ba3642626ca4 Mon Sep 17 00:00:00 2001 From: Leonardo Henrique Romanini Date: Wed, 27 Nov 2024 16:02:23 -0300 Subject: [PATCH] Minor adjusts --- examples/monitoring_alerts/README.md | 3 ++- examples/monitoring_alerts/main.tf | 5 +++-- examples/monitoring_alerts/variables.tf | 6 ++++++ .../monitoring_alerts/monitoring_alerts_test.go | 8 ++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/examples/monitoring_alerts/README.md b/examples/monitoring_alerts/README.md index d754394..5c1bec9 100644 --- a/examples/monitoring_alerts/README.md +++ b/examples/monitoring_alerts/README.md @@ -1,6 +1,6 @@ # Monitoring Alert Example -This example provides monitoring e-mail alerts for KMS key versions scheduled for destruction. If multiple key versions are deleted in less than 5 minutes a single notification will be sent. +This example provides monitoring e-mail alerts for KMS key versions scheduled for destruction. If multiple key versions are deleted in less than 5 minutes, a single notification will be sent. ## Inputs @@ -8,6 +8,7 @@ This example provides monitoring e-mail alerts for KMS key versions scheduled fo | Name | Description | Type | Default | Required | |------|-------------|------|---------|:--------:| | email\_addresses\_to\_be\_notified | Email addresses used for sending notifications to. | `list(string)` | n/a | yes | +| location | Location to create the KMS key and keyring. | `string` | `"us-central1"` | no | | monitor\_all\_keys\_in\_the\_project | True for all KMS key versions under the same project to be monitored, false for only the KMS key version created in this example to be monitored. Default: false. | `bool` | n/a | yes | | project\_id | The ID of the project in which to provision resources. | `string` | n/a | yes | diff --git a/examples/monitoring_alerts/main.tf b/examples/monitoring_alerts/main.tf index e80b999..89bbe92 100644 --- a/examples/monitoring_alerts/main.tf +++ b/examples/monitoring_alerts/main.tf @@ -16,9 +16,10 @@ /** * Send a warning email when a KMS key version is scheduled for destruction. - * If multiple key versions are deleted in less than 5 minutes a single notification will be sent. + * If multiple key versions are deleted in less than 5 minutes, a single notification will be sent. */ +# See all the request types available for google.cloud.kms.v1 here: https://cloud.google.com/kms/docs/reference/rpc/google.cloud.kms.v1. For this example specifically we are monitoring and alerting DestroyCryptoKeyVersionRequest. 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]}/.*\"" @@ -36,7 +37,7 @@ module "kms" { project_id = var.project_id keyring = "alert-keyring-${random_string.suffix.result}" - location = "us-central1" + location = var.location keys = ["alert-key"] prevent_destroy = false } diff --git a/examples/monitoring_alerts/variables.tf b/examples/monitoring_alerts/variables.tf index 5cc6e29..75317c3 100644 --- a/examples/monitoring_alerts/variables.tf +++ b/examples/monitoring_alerts/variables.tf @@ -28,3 +28,9 @@ variable "email_addresses_to_be_notified" { type = list(string) description = "Email addresses used for sending notifications to." } + +variable "location" { + type = string + description = "Location to create the KMS key and keyring." + default = "us-central1" +} diff --git a/test/integration/monitoring_alerts/monitoring_alerts_test.go b/test/integration/monitoring_alerts/monitoring_alerts_test.go index 3a5d880..0d7562e 100644 --- a/test/integration/monitoring_alerts/monitoring_alerts_test.go +++ b/test/integration/monitoring_alerts/monitoring_alerts_test.go @@ -30,6 +30,14 @@ import ( func TestMonitoringAlertKeyVersion(t *testing.T) { + // This test will run 2 iterations based on the following TfInputs variable. + // Map's key (monitor_all_keys_in_the_project): + // - "true" means we are testing the use case where we monitor all the KMS keys in the project. + // - "false" means we are testing the use case where we monitor a single KMS key in the project. + // Map's values (fixture_path): + // We are loading the fixture instead of the example directly because we need to pass the mentioned + // above's boolean to terraform input in order to have the described behavior. + TfInputs := map[bool]string{ true: "../../fixtures/monitoring_alerts_on_project", false: "../../fixtures/monitoring_alerts_specific_key",