I have Anomaly Cost Detection alert created in Azure Subscription -> Cost Management -> Cost Alerts. The alert was created manually via Azure Portal.
As I have created an ARM template that will deploy few other "standard Azure Monitor" alerts upon creation of Azure Subscription, I want to find a way to enable/disable this alert using ARM template so that I can include it in the list.
What I understood is that the alert is extension and cannot exist as a resource by itself, and the documentation states that needs to be attached to other resource. Does anyone have an idea to which one? Also, the documentation states "To create a Microsoft.CostManagement/alerts resource, add the following JSON to your template.", can anyone suggest a template where I can indeed add this resource?
MS Docs Link:
https://learn.microsoft.com/en-us/azure/templates/microsoft.costmanagement/2019-11-01/alerts?pivots=deployment-language-arm-template
2
Answers
I have found a solution to the issue, namely a different type of resource provider was needed. The correct template to use is documented here:
[https://learn.microsoft.com/en-us/azure/templates/microsoft.costmanagement/scheduledactions?pivots=deployment-language-arm-template][1]
The bicep version might be easier to use, but I have managed to deploy this template using AzureResourceManagerTemplateDeployment task in Azure DevOps pipeline.
To create a
Microsoft.CostManagement/alerts
resource for the test purpose, I fetch the template snapshot from my resource group.You’ll need to add the following snippet to your ARM template:
Replace the alert name and resource group name from the that associate with the alert.
The
"properties"
section allows you to configure the alert further. You can specify properties such as thresholds, frequency, and actions to take when the alert triggers.Save the template with alerts as
azuredeploy.json
now run the commands
Once the deployment is successful, navigate to the Azure portal Go to the resource group where you deployed the template Verify that the Cost Management alert is associated with the specified resource group.
Reference:
https://learn.microsoft.com/en-us/azure/templates/microsoft.costmanagement/alerts?pivots=deployment-language-terraform
https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/export-template-portal
https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/resource-manager-alerts-log?tabs=json