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
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.
But the above functionality is not suited for your environment as you mentioned this statement.
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.
Now go to this deployed resource in Portal and visit
Automation >> Export Template
as shown below.Refer Export Template MS Doc.
Once the relevant Json template has generated, click on
Deploy
option and it redirects you to thecustom deployment
page. Now chooseEdit template
option on the top of the page and add below code with modified scope (workspace ID
) as shown below.After applying the modifications, click on
Save
and proceed toReview + create,
then selectCreate
. This will initiate the deployment of an updated resource with the existing configuration by changing a newscope
property and value.I have just tried in simple Microsoft.Insights/scheduledQueryRules rest api
Simple rest api eliminates the uncertainty caused by arm template
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.