DEV Community

Cover image for Deploy Virtual Machines via ARM Template
Celestina Odili
Celestina Odili

Posted on

Deploy Virtual Machines via ARM Template

Contents
Introduction
1: Sign in to the Azure Portal
2: Start a Custom Deployment
3: Select the ARM Template
4: Enter or Load the ARM Template
5: Configure Deployment Settings
6: Verify the Deployment
7: Test Connection

Introduction

Azure Resource Manager (ARM) template is a JSON file that defines the infrastructure and configuration of your Azure resources. It allows deployment, management and configuration of resources in a consistent and repeatable way. ARM templates are a core component of infrastructure as code (IaC) in Azure, enabling automation and deployment at scale. Deploying a virtual machine using an ARM template in Azure Portal is via "Custom deployment". Here is a step-by-step guide:

1. Sign in to the Azure Portal

  • Go to the Azure Portal and log in with your Azure credentials.

2. Start a Custom Deployment

  • In the Azure Portal, search for "Deploy a custom template" in the search bar and select it.

Image description

back to contents

3. Select the ARM Template

  • On the Custom deployment page, you can:
    • "Build your own template in the editor": This allows you to create or edit an ARM template directly in the Azure Portal.
    • Choose from "common templates" if it is among the lists.
    • "Start with a QuickStart template or template spec": This allows you to select existing template file or upload a JSON file that contains your template. Choose either option based on your preference. In this guide, we will be using QuickStart template.

Image description

back to contents

4. Enter or Load the ARM Template

  • If you selected "Build your own template in the editor":
    • Click on "Build your own template in the editor".
    • In the editor, delete the content, paste your ARM template JSON and edit if necessary or write a new one. Here is an example template for deploying a Linux VM:
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
      "type": "Microsoft.Compute/virtualMachines",
      "apiVersion": "2022-08-01",
      "name": "[parameters('vmName')]",
      "location": "[resourceGroup().location]",
      "properties": {
        "hardwareProfile": {
          "vmSize": "[parameters('vmSize')]"
        },
        "storageProfile": {
          "imageReference": {
            "publisher": "[parameters('imagePublisher')]",
            "offer": "[parameters('imageOffer')]",
            "sku": "[parameters('imageSku')]",
            "version": "latest"
          },
          "osDisk": {
            "createOption": "FromImage"
          }
        },
        "osProfile": {
          "computerName": "[parameters('vmName')]",
          "adminUsername": "[parameters('adminUsername')]",
          "adminPassword": "[parameters('adminPassword')]",
          "linuxConfiguration": {
            "disablePasswordAuthentication": false
          }
        },
        "networkProfile": {
          "networkInterfaces": [
            {
              "id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaceName'))]"
            }
          ]
        }
      }
    },
    {
      "type": "Microsoft.Network/networkInterfaces",
      "apiVersion": "2022-08-01",
      "name": "[parameters('networkInterfaceName')]",
      "location": "[resourceGroup().location]",
      "properties": {
        "ipConfigurations": [
          {
            "name": "ipconfig1",
            "properties": {
              "subnet": {
                "id": "[parameters('subnetId')]"
              },
              "privateIPAllocationMethod": "Dynamic",
              "publicIPAddress": {
                "id": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIpAddressName'))]"
              }
            }
          }
        ]
      }
    },
    {
      "type": "Microsoft.Network/publicIPAddresses",
      "apiVersion": "2022-08-01",
      "name": "[parameters('publicIpAddressName')]",
      "location": "[resourceGroup().location]",
      "properties": {
        "publicIPAllocationMethod": "Dynamic"
      }
    }
  ],
  "parameters": {
    "vmName": {
      "type": "string"
    },
    "vmSize": {
      "type": "string",
      "defaultValue": "Standard_B1s"
    },
    "adminUsername": {
      "type": "string"
    },
    "adminPassword": {
      "type": "securestring"
    },
    "networkInterfaceName": {
      "type": "string"
    },
    "publicIpAddressName": {
      "type": "string"
    },
    "subnetId": {
      "type": "string",
      "metadata": {
        "description": "The resource ID of the subnet."
      }
    },
    "imagePublisher": {
      "type": "string",
      "defaultValue": "Canonical"
    },
    "imageOffer": {
      "type": "string",
      "defaultValue": "UbuntuServer"
    },
    "imageSku": {
      "type": "string",
      "defaultValue": "18.04-LTS"
    }
  }
}

Enter fullscreen mode Exit fullscreen mode
  • Click "Save" when done

Image description

  • If you selected "Start with a QuickStart template or template spec": Here we will use QuickStart template.
    • Click on "QuickStart template".
    • Search QuickStart template and select your desired VM template file. Here, we will be selecting a simple Linux VM
    • Click Select template to load the template or Edit template if you want to change some parameters.

Image description

back to contents

5. Configure Deployment Settings

  • After saving or loading the template, you will be taken to the Custom deployment page.
  • Select Subscription
  • Select an existing Resource Group or create a new one.
  • Choose Region
  • Enter the required Parameters like VM name, size, etc.). These are all defined in your ARM template.
  • Choose authentication type (SSH public key or password) Here, we are using password. provide Admin Username and password. Take note of the username and password because they will be needed for connection.
  • Click Review and Create to review the configuration summary.

Image description

Image description

  • Click "Create" to start the deployment.
  • The deployment process will begin, and you can monitor its progress in the Notifications area.

back to contents

6. Verify the Deployment

  • Once the deployment is complete, click go to resource group. This will take you to the Resource group you specified.

Image description

  • You should see the virtual machine and any associated resources (like network interfaces, disks, Virtual network etc.).

Image description

back to contents

7. Test Connection

  • Go to the VM overview page and copy the public IP address

Image description

  • Launch your command terminal (bash for Linux OS and PowerShell for windows OS) and run the following command by replacing username with the username you created and public-ip with the public IP address copied earlier.
ssh username@public-ip
Enter fullscreen mode Exit fullscreen mode
  • Type yes to verify fingerprint and put your password. When typing your password, the characters will not be displayed but if correctly typed, you will get a welcome message indicating a successful connection and the name of your Linux VM will be displayed.

Image description

back to contents

Top comments (0)