I need to create alerts for multiple vms using terraform. Has someone got a simple example I could use, for example:
I want to monitor azure virtual machines called vm01, vm01, vm03 in Resource Group called Rg1. I want to monitor CPU usage and Memory for example. Can someone help with a simple example I can then build on?
You can try this:
resource "azurerm_resource_group" "rg" {
name = "example-rg"
location = "northeurope"
}
resource "azurerm_monitor_action_group" "ag" {
name = "myactiongroup"
resource_group_name = azurerm_resource_group.rg.name
short_name = "exampleactiongroup"
}
resource "azurerm_monitor_metric_alert" "alert" {
name = "example-metricalert"
resource_group_name = azurerm_resource_group.rg.name
scopes = ["/subscriptions/1234xxx"]
description = "description"
target_resource_type = "Microsoft.Compute/virtualMachines"
criteria {
metric_namespace = "Microsoft.Compute/virtualMachines"
metric_name = "Percentage CPU"
aggregation = "Total"
operator = "GreaterThan"
threshold = 80
}
action {
action_group_id = azurerm_monitor_action_group.ag.id
}
}
Terraform provider doc for Azure alerts is here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.