Cloning resources group into another

52 Views Asked by At

Is it possible in Azure to clone one group of resources into another?

I tried to use "Export Template" in azure for this, but when I deployed this template, some resources did not load and I could not figure out why. Is there another way to do this? For example, something like through the azure cloud shell?

fail deploy: fail deploy

1

There are 1 best solutions below

1
Vinicius Deschamps On

Most likely it will fail because of parameters that must be unique across Azure, for example DNS labels for Public IPs or App Services fully qualified domains, so you'll need to change those (and this can be a huge effort depending how many resources you have)

I found some alternatives, that I haven't tested to be honest but they look promising

  1. RGCOPY

RGCOPY (Resource Group COPY) is a tool that copies the most important resources of an Azure resource group (source RG) to a new resource group (target RG). It can copy a whole landscape consisting of many servers within a single Azure resource group to a new resource group.

And it does support the following resources

  • Microsoft.Compute/virtualMachines
  • Microsoft.Compute/disks
  • Microsoft.Network/virtualNetworks
  • Microsoft.Network/networkSecurityGroups
  • Microsoft.Network/networkInterfaces
  • Microsoft.Network/publicIPAddresses
  • Microsoft.Network/publicIPPrefixes
  • Microsoft.Network/loadBalancers
  • Microsoft.Network/natGateways
  • Microsoft.Compute/availabilitySets
  • Microsoft.Compute/proximityPlacementGroups
  • Microsoft.Compute/virtualMachineScaleSets
  • Microsoft.Network/bastionHosts

All other resources in the source Resource RG are skipped and not copied to the target RG

  1. Export-AzResourceGroup

The Export-AzResourceGroup cmdlet captures the specified resource group as a template and saves it to a JSON file.This can be useful in scenarios where you have already created some resources in your resource group, and then want to leverage the benefits of using template backed deployments.

This cmdlet gives you an easy start by generating the template for your existing resources in the resource group. There might be some cases where this cmdlet fails to generate some parts of the template. Warning messages will inform you of the resources that failed. The template will still be generated for the parts that were successful

This is similar to the Export Template that you were using, and there are some limitations

Export is not guaranteed to succeed. Export is not a reliable way to turn pre-existing resources into templates that are usable in production.

When exporting from a resource group or resource, the exported template is generated from the published schemas for each resource type. Occasionally, the schema doesn't have the latest version for a resource type. Check your exported template to make sure it includes the properties you need. If necessary, edit the exported template to use the API version you need.

  1. Copy/Clone script using AzureRM (not entirely sure if that would work)

Copy Resource Groups can be done, but it requires considerable time and effort to manually recreate the network resources, copy the virtual hard disks and attach to newly created virtual machines. To eliminate the manual effort I created a Powershell script

Here is his repository https://github.com/JeffBow/AzurePowerShell, and you will find two scripts to give a shot

References: