Microsoft Azure Documentation

Azure Virtual Machine Templates

Discover how to use and create templates for deploying Azure Virtual Machines efficiently and consistently.

What are VM Templates?

Azure VM templates allow you to define the configuration of your virtual machines, including operating system, disks, networking, and extensions, in a declarative JSON format. This enables repeatable and automated deployments of your Azure infrastructure.

Benefits of Using Templates

Types of Templates

Microsoft Azure primarily uses Azure Resource Manager (ARM) templates for defining and deploying infrastructure resources, including virtual machines.

Azure Resource Manager (ARM) Templates

ARM templates are JSON files that describe the desired state for your Azure deployment. They define the resources you want to deploy and the properties of those resources.

Key components of an ARM template for a VM include:

Example ARM Template Snippet for a VM


{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": {
      "type": "string",
      "metadata": {
        "description": "Name of the virtual machine."
      }
    },
    "adminUsername": {
      "type": "string",
      "metadata": {
        "description": "Admin username for the virtual machine."
      }
    },
    "adminPassword": {
      "type": "securestring",
      "metadata": {
        "description": "Password for the admin user."
      }
    },
    "vmSize": {
      "type": "string",
      "defaultValue": "Standard_DS1_v2",
      "metadata": {
        "description": "Size of the virtual machine."
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.Compute/virtualMachines",
      "apiVersion": "2020-06-01",
      "name": "[parameters('vmName')]",
      "location": "[resourceGroup().location]",
      "properties": {
        "hardwareProfile": {
          "vmSize": "[parameters('vmSize')]"
        },
        "osProfile": {
          "computerName": "[parameters('vmName')]",
          "adminUsername": "[parameters('adminUsername')]",
          "adminPassword": "[parameters('adminPassword')]"
        },
        "storageProfile": {
          "imageReference": {
            "publisher": "MicrosoftWindowsServer",
            "offer": "WindowsServer",
            "sku": "2019-Datacenter",
            "version": "latest"
          },
          "osDisk": {
            "createOption": "FromImage",
            "managedDisk": {
              "storageAccountType": "Standard_LRS"
            }
          }
        },
        "networkProfile": {
          "networkInterfaces": [
            {
              "id": "[resourceId('Microsoft.Network/networkInterfaces', concat(parameters('vmName'), '-nic'))]"
            }
          ]
        }
      }
    }
    // ... other resources like NIC, VNet, Public IP
  ]
}
            

Getting Started with ARM Templates

You can create ARM templates using:

Related Topics

Learn More About ARM Templates