2

我正在尝试使用 terraform 创建资源健康警报,它非常简单非常 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
}

但是,我发现它缺乏进一步设置细粒度警报条件的能力,就像我们只想在当前资源状态降级或不可用时发出警报,并且 reson 类型是平台启动的。Terraform 似乎在满足所有条件。

4

1 回答 1

0

单一资源范围

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_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
}
于 2021-08-05T12:17:31.547 回答