Daniel's Blog

Monitoring Azure Resource Group Status

I ran into an issue updating an Azure resource group. All changes resulted in errors saying:

The resource group 'garbage' is being updated and cannot perform this operation.

It doesn't really describe what was going on so I tested it using the cli:

$ az group list --query "[?name=='garbage']"
[
  {

    "id": "/subscriptions/garbage-fa86-4b7a-a6c0-65fc7fee0f1a/resourceGroups/garbage",

    "location": "somewhereus",

    "managedBy": null,
    "name": "garbage",
    "properties": {
      "provisioningState": "MovingResources"
    },
    "tags": {},
    "type": "Microsoft.Resources/resourceGroups"
  }
]

Now I know its stuck 'MovingResources'. The resource I moved had already finished so who knows why the ResourceGroup's ProvisioningState is still saying that it is Moving them. After some quick searches for help the only solution is to wait for the Moving Resource Operation to timeout. I don't want to run the command over and over again and there's a great program called watch that will do that for me. The issue here is that watch needs quotes and the command to check the Resource Group also has quotes. So how to escape the quotes? This is how:

watch -n 120 'az group list --query "[?name=='\''garbage'\'']"'

What is going on is that every 120 seconds it will run the command to list the group. I can leave that running in another window and then check on it periodically while I do other work. (An ideal scenario would be to write a script or something to alert me, but that's too much work for a small task). The interesting part here is escaping the quotes. What is happening is that the quoted string is getting terminated, an escaped quote is inserted, and then the string is started again. This works and will run the command as expected.