Skip to main content
Jorge Bernhardt Jorge Bernhardt
  1. Posts/

How to export Azure Resource Groups to ARM Templates

·409 words·2 mins· 100 views · 5 likes ·
Azure CLI Azure Cloud Shell Azure PowerShell Export-AzureRmResourceGroup

In this post, I want to show you how to export a Resource Group to an ARM template using the command line. This tutorial assumes that you already have a Microsoft Azure account set up.

Azure PowerShell Workaround>

Azure PowerShell Workaround #

If you want to know how to install the PowerShell Azure module on your machine, check out this link. The simplest way to get started is to sign in interactively at the command line.

Login-AzureRmAccount

This cmdlet will bring up a dialog box prompting you for your email address and password associated with your Azure account. If you have more than one subscription associated with your mail account, you can choose the default subscription. To perform this task, we will use the following commands:

Get-AzureRmSubscription
Select-AzureRmSubscription -Subscription "My Subscription"

With the following command in PowerShell, we obtain the list of existing resource groups in your subscription.

Get-AzureRmResourceGroup `
    | Select-Object ResourceGroupName, Location

Get-AzureRmResourceGroup
If you need to create a new resource group, check out this link. To export a Resource Group using Azure Powershell, you should use the Export-AzureRmResourceGroup cmdlet; this cmdlet captures the specified resource group as a template and saves it to a JSON file. Use the Export-AzureRmResourceGroupt cmdlet with the following syntax:

Export-AzureRmResourceGroup `
    -ResourceGroupName <String> `
    -Path <String>

Export-AzureRmResourceGroup

Azure CLI Workaround>

Azure CLI Workaround #

You can use it in your browser with Azure Cloud Shell or install it on your machine. If you want to know how to install the Azure CLI, check out this link. The way to get started is to sign in interactively at the command line.

az login

This command will bring up a dialog box prompting you for your email address and password associated with your Azure account. If you have more than one subscription associated with your mail account, you can choose the default subscription. To perform this task, we will use the following commands:

az account list
az account set --subscription "Subscription Name"

With the following command in Azure CLI, we obtain the list of existing resource groups in your subscription.

az group list

To create a new resource group with Azure CLI, check out this link. Using the Azure CLI, you can export a resource group within Azure by typing the following command:

az group export \
--name <ResourceGroupName>

ARM Templates

Thanks for reading my post. I hope you find it useful.

If you want to know more about Azure Resource Manager Templates, check out this link.