Last week I had a pretty strange issue with moving Azure SQL VM and related resources to the other resource group. To simplify scenario and make it easier to understand, these are the facts.
- Resource group OLD_RG
- Resource group NEW_RG
- Virtual machine DB01 in OLD_RG (Azure SQL VM with SQL Enterprise)
- Virtual machine DB01 in NEW_RG (Azure SQL VM with SQL Standard)
My client wanted to cut the costs on SQL Server and wanted to change SQL edition from Enterprise to Standard. Plan was to install new Azure SQL VM with Standard edition, but challenge was to keep the same name and IP address. Basically, Azure allows you to create two or more virtual machines with the same name, but only if they are in different resource groups.
So, I created virtual machine DB01 in NEW_RG and configure it. Once client informed me that they finished database moving and other configurations, I have deleted DB01 from OLD_RG. Next logical step was moving DB01 to OLD_RG in order to group resources, but I got error message on validation step.
Duplicate resources with identifiers ‘/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/OLD_RG/providers/Microsoft.SqlVirtualMachine/SqlVirtualMachines/DB01’ were found in resource group ‘OLD_RG’. The tracking Id is xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx’. (Code: DuplicateResources)”
When I checked resource group, there wasn’t any other resources related to “old” SQL VM.
I have tried to perform moving using Azure Portal and Azure PowerShell, but error message was the same every time. After investigation, I have realized that, sometimes, deleting SQL VM will not delete hidden resources that are related to the main resource. In this case, resource type Microsoft.SqlVirtualMachine/SqlVirtualMachines, that represent Azure SQL VM wasn’t deleted, although VM, disks, NIC were deleted successfully. By default, resource types like this are hidden, and will not be visible in Azure Portal until you check the checkbox “Show hidden types”.
TIP: If you check resources using Azure PowerShell, you will be able to list all resources in resource group, included hidden types.
Once I deleted this hidden resource, I was able to perform moving Azure SQL VM to different resources group.