skip to Main Content

The problem is basically that I was trying to update an already existing "Microsoft.Insights/scheduledQueryRules" resource in Azure, but I got a: "Scope can’t be updated (Bad Request)" Error.

What I did was to upload an ARM to update an already existing resource hoping that I could change the scope because I created a new AppInisghts, but It threw the error above.

I’m prety sure that the answer is that this kind of resources can’t have their scopes updated. But why? "Microsoft.Insights/metricAlerts" Can do this 🙁

After researching a little bit I found this issue to some related documentation for migrating alerts https://github.com/MicrosoftDocs/azure-docs/issues/108608

Just wanted to be sure that I’m not able to update the scope and If that’s true warn everybody with this post so they don’t lose time searching for a solution (Because I didn’t find anything claryfying in the official docs)

Thanks everybody.

PD: I’m sure that deleting the resource and creating it again would do the trick but It’s not something I can do right now.

ARM code that you could use to test my problem:

  • Prerequisite: have an existing resource with scope setted

      {
    "type": "Microsoft.Insights/scheduledQueryRules",
    "apiVersion": "2022-08-01-preview",
    "name": "string",
    "location": "string",
    "tags": {
      "tagName1": "tagValue1",
      "tagName2": "tagValue2"
    },
    "kind": "string",
    "identity": {
      "type": "string",
      "userAssignedIdentities": {}
    },
    "properties": {
      "actions": {
        "actionGroups": [ "string" ],
        "customProperties": {}
      },
      "scopes": [ PUT NEW SCOPE HERE ],
    }
    

    }

2

Answers


  1. If you want to update the existed code in ARM, you need to follow below steps as it is not possible to update the scope property directly once the deployment is done.

    Refer MSDoc for the relevant functionality.

    If the resource already exists in the resource group and its settings are unchanged, no operation is taken for that resource. If you change the property values for a resource, the resource is updated with those new values.

    If you try to update the location or type or scope of an existing resource, the deployment fails with an error. Instead, deploy a new resource with the location or type that you need.

    But the above functionality is not suited for your environment as you mentioned this statement.

    I’m sure that deleting the resource and creating it again would do the trick but It’s not something I can do right now.

    Alternative approach to this is using export template option under the resource.

    To achieve it, first I’ve deployed an insight scheduled query rule with scope as virtual machine resource ID and the deployment was succeeded as shown below.

    enter image description here

    Now go to this deployed resource in Portal and visit Automation >> Export Template as shown below.

    Refer Export Template MS Doc.

    enter image description here

    Once the relevant Json template has generated, click on Deploy option and it redirects you to the custom deployment page. Now choose Edit template option on the top of the page and add below code with modified scope (workspace ID) as shown below.

    {
        "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {
            "metricAlerts_mylatalertj_name": {
                "defaultValue": "mylatalertj",
                "type": "String"
            },
            "workspace_externalid": {
                "defaultValue": "/subscriptions/xxxxx/resourcegroups/xxxxx/providers/microsoft.operationalinsights/workspaces/newwsj",
                "type": "String"
            },
            "actiongroups_newact_externalid": {
                "defaultValue": "/subscriptions/xxxxx/resourceGroups/xxxxx/providers/microsoft.insights/actiongroups/newact",
                "type": "String"
            }
        },
        "variables": {},
        "resources": [
            {
                "type": "Microsoft.Insights/metricAlerts",
                "apiVersion": "2018-03-01",
                "name": "[parameters('metricAlerts_mylatalertj_name')]",
                "location": "global",
                "tags": {
                    "Reason": "Repro",
                    "CreatedDate": "2/26/2024 8:08:20 AM",
                    "CreatedBy": "NA",
                    "OwningTeam": "NA"
                },
                "properties": {
                    "description": "This is a metric alert",
                    "severity": 3,
                    "enabled": true,
                    "scopes": [
                        "[parameters('workspace_externalid')]"
                    ],
                    "evaluationFrequency": "PT1M",
                    "windowSize": "PT5M",
                    "criteria": {
                        "allOf": [
                            {
                                "threshold": 0,
                                "name": "1st criterion",
                                "metricName": "<Metric Name>", //As per your requirement
                                "operator": "GreaterThan",
                                "timeAggregation": "Average",
                                "criterionType": "StaticThresholdCriterion"
                            }
                        ],
                        "odata.type": "Microsoft.Azure.Monitor.MultipleResourceMultipleMetricCriteria"
                    },
                    "actions": [
                        {
                            "actionGroupId": "[parameters('actiongroups_newact_externalid')]"
                        }
                    ]
                }
            }
        ]
    }
    

    After applying the modifications, click on Save and proceed to Review + create, then select Create. This will initiate the deployment of an updated resource with the existing configuration by changing a new scope property and value.

    enter image description here

    Login or Signup to reply.
  2. I have just tried in simple Microsoft.Insights/scheduledQueryRules rest api

    Simple rest api eliminates the uncertainty caused by arm template

    enter image description here

    re-produce the same error message, I think it’s a build-in feature.
    It is recommended that you directly change the name of the alert and redeploy a new alert.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search