3

I'm trying to use terraform to create resource health alert, it's pretty simple very terraform

resource "azurerm_monitor_activity_log_alert" "resourcehealth" {
  name                = "${var.client_initial}-MCS Optimise Resource Health"
  description         = "${var.client_initial}-MCS Optimise Resource Health Alerts"
  resource_group_name = var.resource_group_name
  scopes              = [var.scopes]
  criteria {
    category = "ResourceHealth"
  }

  action {
    action_group_id = var.action_group_id
  }
  tags = var.tags
}

However, i found it's lack of ability to further set granual alert condition, like we only want alerted on when current resource status is degraded or unavailable, and reson type is platform initiated. Terraform seems to be giving all to all the conditions.

Roger Chen
  • 233
  • 3
  • 15
  • It seams that we cannot do that at the moment : https://github.com/terraform-providers/terraform-provider-azurerm/issues/2996 – Jim Xu Nov 19 '20 at 06:20
  • Hi Jim, indeed, that is for service health, but it's the same for resourc health as well. I have opened another topic https://github.com/terraform-providers/terraform-provider-azurerm/issues/9391 – Roger Chen Nov 19 '20 at 22:00
  • According to the situation, I suggest you use arm template to implement your need. For more details, please refer to https://learn.microsoft.com/en-us/azure/service-health/resource-health-alert-arm-template-guide – Jim Xu Nov 20 '20 at 01:00

1 Answers1

1

Single resource scope

resource "azurerm_monitor_activity_log_alert" "resourcehealth" {
  name                = "${var.client_initial}-MCS Optimise Resource Health"
  description         = "${var.client_initial}-MCS Optimise Resource Health Alerts"
  resource_group_name = var.resource_group_name
  scopes              = [var.scope]
  criteria {
    resource_id    = var.scope
    operation_name = "Microsoft.Resourcehealth/healthevent/Activated/action"
    category       = "ResourceHealth"
  }

  action {
    action_group_id = var.action_group_id
  }
  tags = var.tags
}

For multiple resources use for_each

resource "azurerm_monitor_activity_log_alert" "resourcehealth" {
  for_each = var.scopes

  name                = "${var.client_initial}-MCS Optimise Resource Health"
  description         = "${var.client_initial}-MCS Optimise Resource Health Alerts"
  resource_group_name = var.resource_group_name
  scopes              = [each.key]
  criteria {
    resource_id    = each.key
    operation_name = "Microsoft.Resourcehealth/healthevent/Activated/action"
    category       = "ResourceHealth"
  }

  action {
    action_group_id = var.action_group_id
  }
  tags = var.tags
}
Zaduvalo
  • 39
  • 3