Infrastructure as Code (IaC) is a game-changer for repeatable, scalable cloud deployments. In this guide, you'll learn how to deploy a Virtual Machine (VM) on Azure using an ARM (Azure Resource Manager) template — a powerful JSON-based tool for automating your infrastructure setup.
Table of Contents
- What is an ARM Template?
- Prerequisites
- Step 1: Create the ARM Template
- Step 2: Deploy the Template via Azure Portal
- Step 3: Deploy the Template via Azure CLI
- Verify the Deployment
- Conclusion
What is an ARM Template?
An ARM template is a JSON file that defines the infrastructure and configuration for your project. You can use it to declaratively deploy Azure resources such as Virtual Machines, Networks, Storage, and more.
ARM = Azure Resource Manager, which is Azure's deployment and management service.
Prerequisites
•An Azure Account
•Azure CLI or access to the Azure Portal
•Basic understanding of JSON
Step 1: Create the ARM Template
A. On your vs code, click on open folder and create a new folder and select.
B. After selecting, create a file by clicking on the file sign and then name your json file using the json extension.
C. create your content following json file format. save after creating it. It will automatically save on the new folder created.
Step 2: Deploy the Template via Azure Portal
1.Go to the Azure Portal
2.Search for Deploy a custom template
3.Choose Build your own template in the editor
4.Paste your azuredeploy.json content
5.Click Save
6.Fill in required parameters (VM name, admin username, password)
7.Click Review + Create, then Create
Template export:
If you want to recreate the VM next time with the same configuration, on the VM overview,
go to automation and click export template. You can download or copy content.
Arm template upload via azure portal.
Another way to create resources using arm template on the azure portal is the use of the upload option. follow below steps.
- search for deploy a custom template and enter
- Build your own template in the editor
- upload file
- Fili up the parameters
- Review and create
Resources deployed
Step 3: Deploy the Template via Azure CLI
If you prefer command-line, you can also deploy using the Azure CLI:
First of all you need to install azure CLI. Using this link: https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest&tabs=azure-cli&pivots=msi
Install the latest version and run below azure CLI
Log in to Azure
- az login. This command opens a web browser to authenticate your account. After authentication, on your terminal, select git bash to run below vm create commands.
az vm create
--resource-group RG1
--name MyVM
--image Ubuntu2204
--admin-username azureuser `
--generate-ssh-keys
If VM is successfully created, you will see below image. If not failed, you will get error an message.
Verify the Deployment
Once deployed:
•Go to Azure Portal → Resource Groups → RG1
•You should see a VM and related resources (depending on your full template setup)
•You can also SSH into the VM (if you configure a public IP and open port 22)
Check out these command lines
**#to start a VM
az vm start --resource-group RG1 --name MyVM
to stop a VM
az vm stop --resource-group RG1 --name MyVM
to delete a VM
az vm delete --resource-group RG1 --name MyVM –yes**
to delete the VM just created, let us run commadn line az vm delete --resource-group RG1 --name MyVM
To delete the resource group run this command az group delete --name RG1 --yes --no-wait.
To confirm deletion was successful, you can run az group show --name RG1. It will show resource group not found. You can also check via the portal.
Use below link to find many azure command lines.
https://docs.google.com/document/d/1tC5e8LCrlR-2nLL33VF3nzIOXAXQ0K4FMxRNTx_qyaw/edit?tab=t.0
Conclusion
You’ve just learned how to:
•Write a basic ARM template
•Deploy it through Azure Portal and Azure CLI
•Automate VM deployments with Infrastructure as Code
ARM templates give you the flexibility and control to provision complex environments with a single JSON file.
Top comments (0)