'Azure ARM template creating duplicate resources

Deploying incrementally an ARM template with a simple Application Insight resource, is automatically creating FailureAnomaliesDetector alert rule. Which is a problem in case such rule already exists.

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "resources": [
        {
            "type": "Microsoft.Insights/components",
            "apiVersion": "2020-02-02",
            "location": "[resourceGroup().location]",
            "name": "AiApp",
            "kind": "web",
            "properties": {
                "Application_Type": "web",
                "IngestionMode": "ApplicationInsights",
                "SamplingPercentage": 12.5,
                "publicNetworkAccessForIngestion": "Enabled",
                "publicNetworkAccessForQuery": "Enabled"
            }
        },
        {
            "type": "microsoft.insights/actionGroups",
            "apiVersion": "2019-06-01",
            "name": "ActionGroup",
            "location": "Global",
            "properties": {
                "groupShortName": "AiApp",
                "enabled": true,
                "emailReceivers": "[createObject('emailAddress','[email protected]','name','email','useCommonAlertSchema',true())]"
            },
            "dependsOn": [ "[resourceId('microsoft.insights/components', 'AiApp')]" ]
        },
        {
            "type": "microsoft.alertsmanagement/smartdetectoralertrules",
            "apiVersion": "2021-04-01",
            "name": "AlertAnomalies",
            "location": "global",
            "dependsOn": [ "[resourceId('microsoft.insights/actionGroups', 'ActionGroup')]" ],
            "properties": {
                "description": "Failure Anomalies notifies you of an unusual rise in the rate of failed HTTP requests or dependency calls.",
                "state": "Enabled",
                "severity": "Sev2",
                "frequency": "PT1M",
                "detector": {
                    "id": "FailureAnomaliesDetector"
                },
                "scope": [ "[resourceId('microsoft.insights/components', 'AiApp')]" ],
                "actionGroups": {
                    "groupIds": [ "[resourceId('microsoft.insights/actionGroups', 'ActionGroup')]" ]
                }
            }
        }        
    ]
    }

I was not able to find any hint in the documentation to stop it creating for my case unwanted rule. Any Idea?



Solution 1:[1]

We have tried with the below ARM template to create simple Application insight resource and can able to deploy successfully without creating FailureAnomaliesDetector .

TEMPLATE:-

{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"name": {
"type": "string"
},
"type": {
"type": "string"
},
"regionId": {
"type": "string"
},
"tagsArray": {
"type": "object"
},
"requestSource": {
"type": "string"
},
"workspaceResourceId": {
"type": "string"
}
},
"resources": [
{
"name": "[parameters('name')]",
"type": "microsoft.insights/components",
"location": "[parameters('regionId')]",
"tags": "[parameters('tagsArray')]",
"apiVersion": "2020-02-02-preview",
"dependsOn": [],
"properties": {
"ApplicationId": "[parameters('name')]",
"Application_Type": "[parameters('type')]",
"Flow_Type": "Redfield",
"Request_Source": "[parameters('requestSource')]",
"WorkspaceResourceId": "[parameters('workspaceResourceId')]"
}
}

OUTPUT DETAILS:- enter image description here enter image description here

enter image description here

enter image description here

For more information please refer this SO THREAD .

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AjayKumarGhose-MT