Skip to content

Commit

Permalink
Minor adjusts
Browse files Browse the repository at this point in the history
  • Loading branch information
romanini-ciandt committed Nov 27, 2024
1 parent 90ad6c7 commit c0ca534
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion examples/monitoring_alerts/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# 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.

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Inputs

| 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 |

Expand Down
5 changes: 3 additions & 2 deletions examples/monitoring_alerts/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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]}/.*\""
Expand All @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions examples/monitoring_alerts/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
8 changes: 8 additions & 0 deletions test/integration/monitoring_alerts/monitoring_alerts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit c0ca534

Please sign in to comment.