diff --git a/aks/postgres/resources.tf b/aks/postgres/resources.tf index 7129e02..ba73673 100644 --- a/aks/postgres/resources.tf +++ b/aks/postgres/resources.tf @@ -10,6 +10,17 @@ locals { azure_enable_monitoring = var.use_azure && var.azure_enable_monitoring kubernetes_name = "${var.service_name}-${var.environment}-postgres${local.name_suffix}" + + alert_frequency = local.alert_frequency_map[var.alert_window_size] + + alert_frequency_map = { + PT1M = "PT1M" + PT5M = "PT5M" + PT15M = "PT15M" + PT30M = "PT30M" + PT1H = "PT1H" + } + } # Username & password @@ -172,6 +183,7 @@ resource "azurerm_monitor_metric_alert" "memory" { scopes = [azurerm_postgresql_flexible_server.main[0].id] description = "Action will be triggered when memory use is greater than 75%" window_size = var.alert_window_size + frequency = local.alert_frequency criteria { metric_namespace = "Microsoft.DBforPostgreSQL/flexibleServers" @@ -200,6 +212,7 @@ resource "azurerm_monitor_metric_alert" "cpu" { scopes = [azurerm_postgresql_flexible_server.main[0].id] description = "Action will be triggered when cpu use is greater than ${var.azure_cpu_threshold}%" window_size = var.alert_window_size + frequency = local.alert_frequency criteria { metric_namespace = "Microsoft.DBforPostgreSQL/flexibleServers" @@ -228,6 +241,7 @@ resource "azurerm_monitor_metric_alert" "storage" { scopes = [azurerm_postgresql_flexible_server.main[0].id] description = "Action will be triggered when storage use is greater than ${var.azure_storage_threshold}%" window_size = var.alert_window_size + frequency = local.alert_frequency criteria { metric_namespace = "Microsoft.DBforPostgreSQL/flexibleServers" diff --git a/aks/postgres/variables.tf b/aks/postgres/variables.tf index 98beb73..40ce8db 100644 --- a/aks/postgres/variables.tf +++ b/aks/postgres/variables.tf @@ -124,13 +124,21 @@ variable "azure_enable_monitoring" { default = true } + + variable "alert_window_size" { - type = string - nullable = false - default = "PT5M" + type = string + nullable = false + default = "PT5M" + validation { + condition = contains(["PT1M", "PT5M", "PT15M", "PT30M", "PT1H"], var.alert_window_size) + error_message = "The alert_window_size must be one of: PT1M, PT5M, PT15M, PT30M, PT1H." + } description = "The period of time that is used to monitor alert activity e.g PT1M, PT5M, PT15M, PT30M, PT1H, PT6H or PT12H" } + + variable "azure_maintenance_window" { type = object({ day_of_week = optional(number)