ARM templates are a very convenient way to document your azure implementation. You can export the ARM template from your azure subscription based on each resource group and store them in your source control repository to keep track of the changes in your Azure environment. There are two methods in order to get the ARM template out of your resource group in your Azure subscription. You can use portal to get the azure ARM template or you can use Powershell for this purpose (CLI is also available, but I think a few people use it since the availability of Powershell on nix systems)
In this blog post I will provide you a Powershell script to loop through all the resources in all your resource groups and create ARM templates out of each one and save them in your local drive. Then you can use git bash commands to push them to your source control repository.
For an introduction to the Azure ARM template, you can see this post:
Active Azure subscription
At least one resource group with one resource in your subscription
Setup the Powershell on your local machine in order to be able to be connected to your Azure subscription
Some resources are not supported in the ARM template yet. So when you run the Export-AzureRmResourceGroup cmdlet, it shows you some warnings. You have to create those resources manually. But it is good to document what is exported in the ARM template and what is not. For this purpose, I have included an output file to grab all of these info just in case.
There is a limitation of 200 objects that can be exported by this method. If your resource group has more than 200 objects, you should find another way to document your implementation.
You can see how you can export the ARM template from Azure Portal here : https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-export-template
The main powershell command to export the template is Export-AzureRMResourceGroup :
I have added reporting functionality and loops to get all the resource groups in your subscription.
$myPath = 'c:\armdownload\'
$subscription = 'mysub'
$basePath = $myPath + $subscription + '\'
$output = $basePath + 'output.txt'
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
Start-Transcript -path $output -append
Get-AzureRmSubscription -SubscriptionName $subscription | Select-AzureRmSubscription
$allresgroup = Get-AzureRmResourceGroup;
foreach ($rg in $allresgroup)
$rsname = $rg.ResourceGroupName
$fullpath = $basePath+$rsname+'.json'
Export-AzureRmResourceGroup -ResourceGroupName $rsname -Path $fullpath -IncludeComments