Azure Resource Manager - Part 6 - Move Azure Resources from one Resource Group to another

Tobias Zimmergren
Tobias Zimmergren
💡🤖TIP: Check out the guidance for AI adoption on Azure!

This article is part of a series. Here's a list of all available parts.

In the past recent months I've been turning inside out on various parts of Azure, including the Azure Resource Manager (ARM) and what it offers.

If you're looking for the basics of getting started, please check out the other posts in this article series. Start here.

Background

I love how we can work with resources in Resource Groups, and keep them grouped for easy findability, configuration and manageability.

One of the things I've been looking for is an automatic way to move resources between my resource groups.

Moving Azure Resources between Resource Groups using REST

In this post we'll quickly check out how to do just that, using the ARM REST API.

Use the Azure Resource Manager REST Api to move resources from one Resource Group to another

I dug into the REST API's for Azure Resource Manager and found that there's now an endpoint for doing this, and it's very straight forward.

The request should be done to the /resourceGroups/<groupName>/moveResources endpoint, which could look like this (replace subscription Id and resource group name with your own:

The POST request

This is a sample of what the POST request endpoint would look like. Replace the SUBSCRIPTIONGUID and RESOURCEGROUPNAME with your own.

POST https://management.azure.com/subscriptions/SUBSCRIPTIONGUID/resourceGroups/Resource-Group-A/moveResources?api-version=2014-04-01

JSON Payload

The payload needs to look like this in your POST request, where you specify the targetResourceGroup for where to move the resources, and any resources to move:

{
  "targetResourceGroup": "/subscriptions/SUBSCRIPTIONGUID/resourceGroups/ZimmersNewResourceGroup",
  "resources": [
    "/subscriptions/SubscriptionGUID/resourceGroups/Bots/providers/Microsoft.Web/sites/slackcodebot"
  ]
}

Example

Pose that we have Resource-Group-A and Resource-Group-B. Resource Group B is empty at the moment, but Resource Group A contains our resources that we want to move:

Resource Group A contains resources

We have two Azure Storage Accounts: zimmerstorage123 and zimmerstorage234. Here's what that exact request would look like in order to move from A to B:

POST https://management.azure.com/subscriptions/c6f21dec-a9b3-4ed9-88b7-946549cb2300/resourceGroups/Resource-Group-A/moveResources?api-version=2014-04-01

{
  "targetResourceGroup": "/subscriptions/c6f21dec-a9b3-4ed9-88b7-946549cb2300/resourceGroups/Resource-Group-B",
  "resources": [
    "/subscriptions/c6f21dec-a9b3-4ed9-88b7-946549cb2300/resourceGroups/resource-group-a/providers/Microsoft.Storage/storageAccounts/zimmerstorage123",
	"/subscriptions/c6f21dec-a9b3-4ed9-88b7-946549cb2300/resourceGroups/resource-group-a/providers/Microsoft.Storage/storageAccounts/zimmerstorage234"
  ]
}

The POST request is targeting Resource-Group-A and in the payload we select the Resource-Group-B as a targetResourceGroup for the resources.

The status of the destination resource group is changed to Moving Resources as expected. After a short while (or a long while, should you have a lot of resources), they now live in your new resource group:

Resource Group B is letting us know that the resources are moving

The result is as expected, that our resources now exist in Resource-Group-B instead of A. Voila, it's that easy.

Resource Group B has the new resources

Feel free to drop any comments or questions in the comments section.
Enjoy.

Azure Resource ManagerAzureREST

Tobias Zimmergren Twitter

Hi, I'm Tobias! 👋 I write about Microsoft Azure, security, cybersecurity, compliance, cloud architecture, Microsoft 365, and general tech!

Reactions and mentions


Hi, I'm Tobias 👋

Tobias Zimmergren profile picture

Find out more about me.

Recent comments

Mastodon