diff --git a/terraform/data.monitor_action_groups.tf b/terraform/data.monitor_action_groups.tf new file mode 100644 index 0000000..660bb83 --- /dev/null +++ b/terraform/data.monitor_action_groups.tf @@ -0,0 +1,45 @@ +provider "azurerm" { + alias = "azure_monitor" + subscription_id = var.environment == "prd" ? "7760848c-794d-4a19-8cb2-52f71a21ac2b" : "d68448b0-9947-46d7-8771-baa331a3063a" + features {} + storage_use_azuread = true +} + +locals { + azure_monitor_resource_group = "rg-platform-monitoring-${var.environment}-uksouth" +} + +data "azurerm_monitor_action_group" "critical" { + provider = azurerm.azure_monitor + + name = "p0-critical-alerts-${var.environment}" + resource_group_name = local.azure_monitor_resource_group +} + +data "azurerm_monitor_action_group" "high" { + provider = azurerm.azure_monitor + + name = "p1-high-alerts-${var.environment}" + resource_group_name = local.azure_monitor_resource_group +} + +data "azurerm_monitor_action_group" "moderate" { + provider = azurerm.azure_monitor + + name = "p2-moderate-alerts-${var.environment}" + resource_group_name = local.azure_monitor_resource_group +} + +data "azurerm_monitor_action_group" "low" { + provider = azurerm.azure_monitor + + name = "p3-low-alerts-${var.environment}" + resource_group_name = local.azure_monitor_resource_group +} + +data "azurerm_monitor_action_group" "informational" { + provider = azurerm.azure_monitor + + name = "p4-informational-alerts-${var.environment}" + resource_group_name = local.azure_monitor_resource_group +} diff --git a/terraform/resource_health_alerts.tf b/terraform/resource_health_alerts.tf new file mode 100644 index 0000000..444f399 --- /dev/null +++ b/terraform/resource_health_alerts.tf @@ -0,0 +1,23 @@ +resource "azurerm_monitor_activity_log_alert" "rg_resource_health" { + name = "portal-repository-${var.environment} - ${azurerm_resource_group.rg.name} - resource health" + + resource_group_name = azurerm_resource_group.rg.name + location = "global" + + scopes = [azurerm_resource_group.rg.id] + description = "Resource health alert for ${azurerm_resource_group.rg.name} resource group" + + criteria { + category = "ResourceHealth" + + resource_health { + previous = ["Available"] + } + } + + action { + action_group_id = var.environment == "prd" ? data.azurerm_monitor_action_group.critical.id : data.azurerm_monitor_action_group.informational.id + } + + tags = var.tags +}