DEV Community

Cover image for Deploy a Virtual Machine Using an ARM Template on azure
Simonpeter Ebuka
Simonpeter Ebuka

Posted on • Edited on

Deploy a Virtual Machine Using an ARM Template on azure

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

  1. What is an ARM Template?
  2. Prerequisites
  3. Step 1: Create the ARM Template
  4. Step 2: Deploy the Template via Azure Portal
  5. Step 3: Deploy the Template via Azure CLI
  6. Verify the Deployment
  7. 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.

Image description
B. After selecting, create a file by clicking on the file sign and then name your json file using the json extension.

Image description
C. create your content following json file format. save after creating it. It will automatically save on the new folder created.

Image description

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

Image description

Image description

Image description

Image description

Image description

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.

Image description

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.

  1. search for deploy a custom template and enter
  2. Build your own template in the editor
  3. upload file
  4. Fili up the parameters
  5. Review and create

Image description

Image description

Image description

Image description

Image description

Resources deployed

Image description

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

  1. 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

Image description
If VM is successfully created, you will see below image. If not failed, you will get error an message.

Image description
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)

Image description

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

Image description
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.

Image description
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)