A great feature in Azure is the possibility to move resources to:
– Another resource group
– Another subscription
– Another region
The list of resources that you can move is available here: Move operation support by resource type – Azure Resource Manager | Microsoft Docs
In this example, I will move a MySQL Database Server from a subscription A to a subscription B. By the portal, it is easy, but it can take a long time to do the validation and the move:
After waiting each time the long validation period, I find another way to do not wait so many time: with CLI.
The first command to execute to validate that we can do the move is az resource invoke-action. Let’s do this for our resource:
1 2 |
az login az resource invoke-action --action validateMoveResources --ids "/subscriptions/8f42d475-dbd8-4670-9ad3-429d648a4ebb/resourceGroups/Starwind" --request-body "{ \"resources\": [\"/subscriptions/8f42d475-dbd8-4670-9ad3-429d648a4ebb/resourceGroups/Starwind/providers/Microsoft.DBforMySQL/servers/starwinddb\"],\"targetResourceGroup\":\"/subscriptions/ce6d976b-5197-4ae5-8467-173ddf912b64/resourceGroups/Starwind\" }" |
If the answer is empty, you are good to go to move the resource. Otherwise, you will have the error, for example, if you use Private Endpoint, you will not be able to move your resource:
In my case I can move the resource. I will use the az resource move command to do the job:
1 2 3 |
az account set -s 8f42d475-dbd8-4670-9ad3-429d648a4ebb db=$(az resource show -g Starwind -n starwinddb --resource-type "Microsoft.DBforMySQL/servers" --query id --output tsv) az resource move --destination-group Starwind --ids $db --destination-subscription-id ce6d976b-5197-4ae5-8467-173ddf912b64 |
After few minutes, we can see that the resource moved to the other subscription:
Like this it is very simple to automate the move of resources to another resource group/subscription/region. The only limitation is that not all resources can move at this time.