diff --git a/modules/monitoring-tools/README.md b/modules/monitoring-tools/README.md new file mode 100644 index 0000000..9a1d360 --- /dev/null +++ b/modules/monitoring-tools/README.md @@ -0,0 +1,45 @@ + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >=1.7 | +| [google](#requirement\_google) | >= 5.22.0 | +| [google-beta](#requirement\_google-beta) | >= 5.22.0 | + +## Providers + +| Name | Version | +|------|---------| +| [google](#provider\_google) | >= 5.22.0 | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [google_monitoring_alert_policy.main](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_alert_policy) | resource | +| [google_monitoring_notification_channel.main](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/monitoring_notification_channel) | resource | +| [google_project_service.main](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/project_service) | resource | +| [google_project.main](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/project) | data source | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [channels](#input\_channels) | Channel variable that contains `error` and `warn` as keys | `map(string)` | n/a | yes | +| [location](#input\_location) | The location of the resource. | `string` | n/a | yes | +| [project\_id](#input\_project\_id) | The ID of Google Cloud Platform. | `string` | n/a | yes | +| [secrets](#input\_secrets) | The token required for notifications to Slack.
The variable is required for monitoring. | `string` | n/a | yes | +| [target](#input\_target) | The target information for monitoring.
`base_value` is used to calculate a numeric value based on the target resource.
Specifically, it is used to obtain a percentage, as in `floor(base_value * threshold.value)`. |
object({
title = string
metric = string
resource_type = string
label = string
name = string
filter = string
reducer = string
aligner = string
base_value = optional(number, 1)
threshold = map(
object({
value = number
window = string
})
)
})
| n/a | yes | + +## Outputs + +| Name | Description | +|------|-------------| +| [enabled\_apis](#output\_enabled\_apis) | Already enabled APIs list. | +| [policies](#output\_policies) | Alert policies name object. | + \ No newline at end of file diff --git a/modules/monitoring-tools/alert.tf b/modules/monitoring-tools/alert.tf new file mode 100644 index 0000000..eb59cb5 --- /dev/null +++ b/modules/monitoring-tools/alert.tf @@ -0,0 +1,45 @@ +resource "google_monitoring_alert_policy" "main" { + for_each = local.levels + + display_name = "[${upper(each.value)}] ${var.target.name} ${var.target.title}" + + conditions { + display_name = "[${upper(each.value)}] ${var.target.name} - ${var.target.title}" + + condition_threshold { + filter = <