Clone your Azure Resource Group with ARM and Bicep
One common task for cloud engineers is setting up an environment in Azure for solution development. During the development and prototyping phases of an architecture, various manual tasks are performed to test different aspects. However, when it comes to recreating this environment in another resource group, the manual approach becomes impractical. This is where the use of Infrastructure as Code (IaC) becomes crucial, employing tools such as ARM, Terraform, or Bicep.
Retrieving all the settings from your “click-and-test” runs isn’t a straightforward process, and there’s a risk of forgetting crucial elements. To streamline this, I often rely on a simple script. This script allows me to extract the entire ARM/Bicep environment from one resource group and apply it to another for testing purposes. Alternatively, I can extract specific settings directly from the file to incorporate them into new Bicep files.
# Resourcegroup
$resourceGroup = 'myresourcegroup'
# Path to ARM Template
$armTemplatePath = "./armexport.json"
# Path to bicep file
$bicepOutputPath = "./main.bicep"
az group export --name $resourceGroup --output json > $armTemplatePath
# ARM Template in Bicep dekompilieren
az bicep decompile --file $armTemplatePath --force > $bicepOutputPath
az deployment group create --resource-group $resourceGroup --template-file $bicepOutputPath --what-if
If you haven’t installed the Azure CLI (az cli) before, you can do this quite simple with the following command.
Install-Module -Name Az -AllowClobber -Force -Scope CurrentUser
Install-AzCLI
This complex code sample is also on GitHub: https://github.com/oliverscheer/copy-resource-group
Happy environment cloning.
About the Author / Oliver Scheer
Meet Oliver, a Principal Software Engineer at Medialesson, boasting over 25 years of software development expertise across real and challenging customer projects. With 17 years of experience at Microsoft as both an Evangelist and Software Engineer, Oliver's focus lies in .NET, DevOps, Developer Experiences, and Cloud technologies. For more about Oliver, visit his website or LinkedIn profile.