DEV Community

Cover image for Deploying a Virtual Machine Using ARM Template
Romanus Onyekwere
Romanus Onyekwere

Posted on

Deploying a Virtual Machine Using ARM Template

Azure Virtual Machines (VMs) are a key component of cloud computing, providing scalable and flexible infrastructure for various applications and workloads.

In this post, we will explore the process of deploying Azure Virtual Machines using ARM (Azure Resource Manager) templates in Visual Studio Code, a powerful and extensible code editor.

ARM templates enable the definition of the Azure resources needed for your solution in a declarative manner, making it easier to manage and reproduce your infrastructure.

Deploying a virtual machine (VM) using an Azure Resource Manager (ARM) template is a straightforward process. ARM templates allow you to define the infrastructure and configuration for your Azure resources in a declarative JSON format. Below are the steps to deploy a VM using an ARM template:

1.Edit And Deploy a Template

In the Web browser, go to Azure Portal and login
On the Azure portal search bar, search deploy a custom template and select it from the avaliable options
Image description

On the This template will define properties such as VM size, OS image, networking, and storage configurations. You can either write or build the template from scratch or use existing templates from the Azure Quickstart Templates repository.
Using the avaliable Template, you can do the following;
(a) Create a Linux Vm
(b) Create a Window VM
(C) Create a Web App
(d) Create SQL database
(e) Create Azure Landing Zone
We are concentrating on building on our own template
Click on build your own template with the editor
Image description

You can as well use the Quickstart template disclaimer dropdown to select template repository of your choice.

Image description

You will see a blank template
Image description
Replace the blank template with the following template. It deploys a virtual network with a subnet.
Click Save

Image description
You will see Custom Deployment Window
Under Project details, choose your subscription and Create a new resource group, But you can use the existing one
Leave other parameters at default values.
Then Click Review and Create

Image description
After the portal finished template validation, click on Create
When the deployment completes, you see the status of the deployment. This time select the name of the resource group and go to resource

Image description
You will notice that your resource group now contains a storage account and a virtual network.
To locate your resource group page, you can click on the name of the resource group you created or search the resource group name under resource group on the Azure portal

Image description
Click on the resource group to see the Window Overview

Image description

2.Export a Custom Template

One of the easiest way to work with an ARM template is to have the portal generate it for you. The portal can create an ARM template based on the current state of your resource group.
On the oveview page of the VNET, Click Autmation at the left menu
Under automation you will see export template and click it
Your template will be generated

Image description
The portal generates a template for you based on the current state of the resource group. Notice that this template is not the same as either template you deployed earlier. It contains definitions for both the storage account and virtual network, along with other resources like a blob service that was automatically created for your storage account.
To save this template for later use, select Download.

Image description

You can reuse the downloaded file after download is completed
Locate the folder and unzip and click the template.jason

Image description

It wil open in VSCode portal
Image description

You now have an ARM template that represents the current state of the resource group. This template is auto-generated. Before using the template for production deployments, you may want to revise it, such as adding parameters for template reuse.

3.How To Clean Up Your Resources

When the Azure resources are no longer needed, clean up the resources you deployed by deleting the resource group.

In the Azure portal, select Resource groups on the left menu.
Enter the resource group name in the Filter for any field search box.
Select the resource group name. You shall see the storage account in the resource group.
Select Delete resource group in the top menu

Top comments (0)