I am trying to deploy below guest metric alert for all VMs under my subscription using terraform,But its throwing below error.
Error: Error creating or updating metric alert "Memory Usage Alert" (resource group "MyTemp"): insights.MetricAlertsClient#CreateOrUpdate: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="BadRequest" Message="Multi-resource alert rules are not supported for metrics in the Azure.VM.Windows.GuestMetrics namespace.
Looking at above error when I dig more in it , for guest metric multi resources are not supported.
I want to know is there any way we can pass mutliple Virtual machines and then run in for loop or something like that so that it will deploy the alert one by one on all VMs mentioned in list.?
Below is the Terraform template which is working absolutely fine for Platform Metrics and not for Guest Metrics.
data "azurerm_subscription" "current" {
subscription_id = var.subscription_id //it will get the current subscription id
}
resource "azurerm_monitor_metric_alert" "myalert" {
name = "Memory Usage Alert"
resource_group_name = "MyTemp" //resource name to which you want to deploy this alert
scopes = [data.azurerm_subscription.current.id]
description = "Action will be triggered when Memory Usage is greater than 85."
target_resource_type = "Microsoft.Compute/virtualMachines"
target_resource_location = "centralindia"
frequency = "PT30M"
window_size = "P1D"
severity = "2"
enabled = "true"
criteria {
metric_namespace = "Azure.VM.Windows.GuestMetrics"
metric_name = "Memory\\% Committed bytes in use"
aggregation = "Average"
operator = "GreaterThanOrEqual"
threshold = 85
}
action {
action_group_id = "/subscriptions/xxxxxxxx/resourceGroups/xxxxx/providers/Microsoft.Insights/actionGroups/xxxxxxx"
}
}