Not able to deploy the ARM template using ADO pipeline getting error "contains an invalid scope, expected a resource group scope but found a subscription scope"

Pradeep Kumar Ramagiri 40 Reputation points
2023-12-14T21:25:39.4266667+00:00
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "alertName": {
            "type": "string",
            "metadata": {
                "description": "The name of the alert rule."
            }
        },
        "resourceId": {
            "type": "string"
        },
        "subscriptionId": {
            "type": "string"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Insights/actionGroups",
            "apiVersion": "2018-03-01",
            "name": "SubHealth",
            "location": "Global",
            "properties": {
                "groupShortName": "ERC",
                "enabled": true,
                "emailReceivers": [
                    {
                        "name": "CTS-Email",
                        "emailAddress": "******@gmail.com"
                    }
                ]
            }
        },
        {
            "type": "Microsoft.Insights/activityLogAlerts",
            "apiVersion": "2017-04-01",
            "name": "[parameters('alertName')]",
            "location": "Global",
            "dependsOn": [
                "Microsoft.Insights/actionGroups/SubHealth"
            ],
            "properties": {
                "enabled": true,
                "description": "This is the description of the alert rule.",
                "scopes": [
                    "/subscriptions/[parameters('subscriptionId')]"
                ],
                "condition": {
                    "allOf": [
                        {
                            "field": "category",
                            "equals": "ServiceHealth"
                        },
                        {
                            "anyOf": [
                                {
                                    "field": "properties.incidentType",
                                    "equals": "Incident"
                                },
                                {
                                    "field": "properties.incidentType",
                                    "equals": "Planned Maintenance"
                                }
                            ]
                        },
                        {
                            "field": "properties.impactedServices[*].ServiceName",
                            "containsAny": [
                                "ExpressRoute \\ ExpressRoute Circuits"
                            ]
                        }
                    ]
                },
                "actions": {
                    "actionGroups": [
                        {
                            "actionGroupId": "[resourceId('Microsoft.Insights/actionGroups', 'SubHealth')]",
                            "webhookProperties": {}
                        }
                    ]
                }
            }
        }
    ]
}


Hi Team,
Iam not able to deploy the ARM template using ADO pipeline getting error "contains an invalid scope, expected a resource group scope but found a subscription scope"

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

1 answer

Sort by: Most helpful
  1. SwathiDhanwada-MSFT 18,996 Reputation points Moderator
    2023-12-19T06:45:43.07+00:00

    @Pradeep Kumar Ramagiri Thanks for your question. I have modified the template with below changes and tested the template in azure portal. Its deployed successfully. Kindly try from your end and let me know if you still face the issue.

    {
        "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {
            "alertName": {
                "type": "String",
                "metadata": {
                    "description": "The name of the alert rule."
                }
            }
        },
        "variables": {},
        "resources": [
            {
                "type": "Microsoft.Insights/actionGroups",
                "apiVersion": "2018-03-01",
                "name": "SubHealth",
                "location": "Global",
                "properties": {
                    "groupShortName": "ERC",
                    "enabled": true,
                    "emailReceivers": [
                        {
                            "name": "CTS-Email",
                            "emailAddress": "******@gmail.com"
                        }
                    ]
                }
            },
            {
                "type": "Microsoft.Insights/activityLogAlerts",
                "apiVersion": "2017-04-01",
                "name": "[parameters('alertName')]",
                "location": "Global",
                "dependsOn": [
                    "Microsoft.Insights/actionGroups/SubHealth"
                ],
                "properties": {
                    "enabled": true,
                    "description": "This is the description of the alert rule.",
                    "scopes": [
                        "[subscription().id]"
                    ],
                    "condition": {
                        "allOf": [
                            {
                                "field": "category",
                                "equals": "ServiceHealth"
                            },
                            {
                                "anyOf": [
                                    {
                                        "field": "properties.incidentType",
                                        "equals": "Incident"
                                    },
                                    {
                                        "field": "properties.incidentType",
                                        "equals": "Planned Maintenance"
                                    }
                                ]
                            },
                            {
                                "field": "properties.impactedServices[*].ServiceName",
                                "containsAny": [
                                    "ExpressRoute \\ ExpressRoute Circuits"
                                ]
                            }
                        ]
                    },
                    "actions": {
                        "actionGroups": [
                            {
                                "actionGroupId": "[resourceId('Microsoft.Insights/actionGroups', 'SubHealth')]",
                                "webhookProperties": {}
                            }
                        ]
                    }
                }
            }
        ]
    }
    
    
    

    Reference document : https://learn.microsoft.com/en-us/azure/service-health/resource-health-alert-arm-template-guide#resource-manager-template-options-for-resource-health-alerts

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.