Restore missing resources when moving resources between Azure subscriptions


Recently, when trying to move resources between my subscriptions in Azure, I came across an issue. Here is how I solved it.

Azure subscriptions

When working on Azure, you might have one or more subscriptions for hosting your resources. Subscriptions offer you a way to group related resources and manage their costs. If you work by yourself, you would most likely have a single subscription. But if you a part of specific programs, build complex apps or work with multiple organizations, you will have multiple subscriptions. Once in a while, you might need to move resources between them and this is where things broken for me.

Unable to move Azure Function App to another subscription

Recently, when trying to move Azure Function App and its related Storage account and App Insights, I got an error similar to the following:

{"code":"ResourceMoveProviderValidationFailed","message":"Resource move validation failed. Please see details. Diagnostic information: timestamp '20201120T113627Z', subscription id '123', tracking id '456', request correlation id '789'.","details":[{"code":"ResourceMoveProviderValidationFailed","target":"Microsoft.Web/sites","message":"{\"Code\":\"BadRequest\",\"Message\":\"Please select all the Microsoft.Web resources from 'Contoso' resource group for cross-subscription migration. Also, please ensure destination resource group 'Contoso' doesn't have any Microsoft.Web resources before move operation. Here is the list of resources you have to move together: contoso-api (Microsoft.Web/sites)\\r\\n ASP-Contoso-846d (Microsoft.Web/serverFarms)\\r\\n. Please check this link for more information: https://portal.azure.com/?websitesextension_ext=asd.featurePath%3Ddetectors%2FMigration#resource/subscriptions/123/resourceGroups/Contoso/providers/Microsoft.Web/sites/contoso-api/troubleshoot\",\"Target\":null,\"Details\":[{\"Message\":\"Please select all the Microsoft.Web resources from 'Contoso' resource group for cross-subscription migration. Also, please ensure destination resource group 'Contoso' doesn't have any Microsoft.Web resources before move operation. Here is the list of resources you have to move together: contoso-api (Microsoft.Web/sites)\\r\\n ASP-Contoso-846d (Microsoft.Web/serverFarms)\\r\\n. Please check this link for more information: https://portal.azure.com/?websitesextension_ext=asd.featurePath%3Ddetectors%2FMigration#resource/subscriptions/123/resourceGroups/Contoso/providers/Microsoft.Web/sites/contoso-api/troubleshoot\"},{\"Code\":\"BadRequest\"},{\"ErrorEntity\":{\"ExtendedCode\":\"52036\",\"MessageTemplate\":\"Please select all the Microsoft.Web resources from '{0}' resource group for cross-subscription migration. Also, please ensure destination resource group '{1}' doesn't have any Microsoft.Web resources before move operation. Here is the list of resources you have to move together:{2}. Please check this link for more information: {3}\",\"Parameters\":[\"Contoso\",\"Contoso\",\" contoso-api (Microsoft.Web/sites)\\r\\n ASP-Contoso-846d (Microsoft.Web/serverFarms)\\r\\n\",\"https://portal.azure.com/?websitesextension_ext=asd.featurePath%3Ddetectors%2FMigration#resource/subscriptions/123/resourceGroups/Contoso/providers/Microsoft.Web/sites/contoso-api/troubleshoot\",\"0\"],\"Code\":\"BadRequest\",\"Message\":\"Please select all the Microsoft.Web resources from 'Contoso' resource group for cross-subscription migration. Also, please ensure destination resource group 'Contoso' doesn't have any Microsoft.Web resources before move operation. Here is the list of resources you have to move together: contoso-api (Microsoft.Web/sites)\\r\\n ASP-Contoso-846d (Microsoft.Web/serverFarms)\\r\\n. Please check this link for more information: https://portal.azure.com/?websitesextension_ext=asd.featurePath%3Ddetectors%2FMigration#resource/subscriptions/123/resourceGroups/Contoso/providers/Microsoft.Web/sites/contoso-api/troubleshoot\"}}],\"Innererror\":null}"}]}

Oddly enough, the ASP-Contoso-846d App service plan referred to in the error, was nowhere to be seen. Somehow, I managed to delete an App service plan that was still being used by my Azure Function App. Surprisingly, the Function App was working just fine.

What complicated things further was, that the Function App was running on a Consumption plan, which you can’t create yourself. And if you choose to create a new Function App on a Consumption Plan, Azure creates a new App Service Plan for you, without letting you to choose the name. So how to fix this other than by recreating the Function App?

Create missing App Service Plan using an ARM template

What allowed me to fix the issue, was to recreate the missing App Service Plan using an ARM template. Here is how I did it.

Start with creating a new Azure Function App on a Consumption plan. Configure it the same way as your existing Function App. But when you get to the last step of the wizard named Review + create don’t click the Create button. Instead, use the Download a template for automation link which will let you download the ARM template for provisioning a Function App and an App Service Plan.

The 'Download a template for automation' link highlighted in the Azure portal

After downloading the template, open the parameters.json file in a code editor, find the hostingPlanName property, and set its name to match the name mentioned in the error when moving your resources.

Hosting plan name highlighted in the ARM template in a code editor

After saving your changes, open terminal and provision the Function App using Azure CLI, by executing:

az deployment group create --resource-group <resource-group-name> --template-file template.json

This will recreate the missing App Service Plan and allow you to move your resources to another subscription.

Others found also helpful: