
Motivation:
Let’s say we have an infrastructure in place. There may be a time that we need to replicate the same infrastructure again. Doing it manually will surely give us an error in the migration stages. So, we will be utilizing a service from Azure called Azure Arm Templates to deploy our infrastructure in an idempotent way.
Architecture:

Prerequisites:
- Azure Blob Storage
- Azure Virtual Machine
- Azure Vnet
Azure VNet:
Azure Virtual Network is a network of Azure in the cloud. This VNet can be subdivided into different subnets. For this exercise, we will be creating one VNet with one subnet which is private and is not accessed to the internet. Click on Virtual Networks, fill in the details, and hit Review + create.

Your VNet shall be successfully deployed.

Azure Virtual Machine:
Now we create an Azure Virtual Machine inside the VNet. Click on Azure Virtual Machine, fill in the basic details, select the VNet that you have just created, and hit Review + create.

The deployment shall be completed successfully

Azure Blob Storage:
Let’s create Azure Blob Storage. Click on Storage Accounts, +Create, and fill in the basic details, and hit Review+create.

Your deployment shall be created.

ARM Templates:
ARM Templates are the idempotent way to write infrastructure in the form of JSON for maximum usability. Creating a VM, VNets, and subnets is a very lengthy process and we may have errors on the way while creating them and so for that reason, ARM Templates are preferred. I have already created the ARM Templates and are here on my GitHub. But do not worry I will teach you how to write ARM Templates, more so generate them as it’s quite difficult to write from scratch.
Let’s say I have created some infrastructure and I want to have an ARM Template for it. Go to the Resource Groups, Select Resources, and Export Template.

Then click on the Download button.

You will get template.json and parameter.json. Template.json contains what infrastructure you want to make with its details and parameter.json contains the unique name that you want to give to the resource. For this post, I will be adding my default values. You can add your unique names through parameter.json and enter the commands given below.
After you hit the commands using the CLI it might not work on the fly as you must do some housekeeping on the JSON files like removing the subscription id for dynamic usability and also removing unnecessary key values pairs. For this post, you don’t have to worry as the JSON I have provided works to its fullest. After you open the code here are the commands that you need to enter linearly.
az create group --name prem-vm --location eastus
az deployment group create --resource-group prem-rg --template-file template.json
Demonstration:
As promised on the architecture let’s check on the VM’s and Storage Accounts.


Both of our resources are inside the VNet that we created.
Conclusion:
We have demonstrated how we can leverage Azure ARM Templates to create even the complex infrastructure with ease. This is a bare minimum as we can add more and more to the ARM Templates. There are other tools such as Terraform and Pulumi which we can leverage to write IaC code as well in declarative and imperative ways. The possibilities are endless, the choices are endless and it’s up to you for what you want to make it. If you encounter any problems or have difficulty following the steps, comment below on this post or message me at [email protected]. You can also connect with me on Linkedin and GitHub.
Resources:
[1] Azure Virtual Network: https://docs.microsoft.com/en-us/azure/virtual-network/virtual-networks-overview
[2] ARM templates: https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/overview