Azure Monitor - Terraform Alerts not firing unless portal created alert created

Chris Peacock 1 Reputation point

I've created an Azure Monitor alert using the following Terraform code:

resource "azurerm_monitor_metric_alert" "azureMonitorMetricAlert1VmCpuCritical1" { name = "VM CPU Critical" resource_group_name = var.resourceGroup1Name scopes = [var.logAnalytics1Id] target_resource_type = "" description = "Action will be triggered when Virtual Machine CPU is greater than 95%" frequency = "PT1M" window_size = "PT5M" criteria { metric_namespace = "Microsoft.OperationalInsights/workspaces" metric_name = "Average_% Processor Time" aggregation = "Average" operator = "GreaterThan" threshold = 95 dimension { name = "Computer" operator = "Include" values = ["*"] } } action { action_group_id = } tags = var.tags }

However, this doesn't fire any alerts (email/SMS) unless I manually create an alert, even the same alert and metrics etc, in the portal. It doesn't matter which order; I create the above alert in TF, then manually create another alert; or I manually create an alert then run the TF code. But regardless, without the manually created alert the TF alerts don't fire.

Has anyone else seen this issue?

I've compared the data from the PS cmdlet: Get-AzMetricAlertRuleV2 with both created alerts and they're identical.

Any thoughts?

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
1,919 questions
{count} votes