Azure Compute Templates

Azure Resource Manager (ARM) templates let you define the infrastructure and configuration for your Azure solutions in a declarative JSON file. This guide provides an overview of template structure, best practices, and examples specific to compute resources such as Virtual Machines, Scale Sets, and Containers.

Overview

Templates are composed of several top‑level sections:

Template Schema

The schema URL must be the first property of the template. The latest schema for Azure is:

{
  "$schema": "https://schema.management.azure.com/schemas/2022-09-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  // ...
}

Sample Compute Template

The following example deploys a Windows Server virtual machine with a public IP address.

{
  "$schema": "https://schema.management.azure.com/schemas/2022-09-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vmName": { "type": "string", "defaultValue": "myVM" },
    "adminUsername": { "type": "string", "defaultValue": "azureuser" },
    "adminPassword": { "type": "secureString" },
    "vmSize": { "type": "string", "defaultValue": "Standard_DS1_v2" }
  },
  "variables": {
    "nicName": "[concat(parameters('vmName'), '-nic')]",
    "publicIPName": "[concat(parameters('vmName'), '-pip')]"
  },
  "resources": [
    {
      "type": "Microsoft.Network/publicIPAddresses",
      "apiVersion": "2022-01-01",
      "name": "[variables('publicIPName')]",
      "location": "[resourceGroup().location]",
      "properties": {
        "publicIPAllocationMethod": "Dynamic"
      }
    },
    {
      "type": "Microsoft.Network/networkInterfaces",
      "apiVersion": "2022-01-01",
      "name": "[variables('nicName')]",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPName'))]"
      ],
      "properties": {
        "ipConfigurations": [
          {
            "name": "ipconfig1",
            "properties": {
              "subnet": {
                "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', 'myVnet', 'mySubnet')]"
              },
              "publicIPAddress": {
                "id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPName'))]"
              }
            }
          }
        ]
      }
    },
    {
      "type": "Microsoft.Compute/virtualMachines",
      "apiVersion": "2022-03-01",
      "name": "[parameters('vmName')]",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
      ],
      "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"
          }
        },
        "networkProfile": {
          "networkInterfaces": [
            {
              "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('nicName'))]"
            }
          ]
        }
      }
    }
  ],
  "outputs": {
    "adminUsername": {
      "type": "string",
      "value": "[parameters('adminUsername')]"
    },
    "publicIP": {
      "type": "string",
      "value": "[reference(variables('publicIPName')).ipAddress]"
    }
  }
}

Parameters

Define parameters to make your template reusable and environment‑agnostic.

NameTypeDefaultDescription
vmNamestringmyVMName of the virtual machine.
adminUsernamestringazureuserAdmin user for the VM.
adminPasswordsecureStringSecure admin password.
vmSizestringStandard_DS1_v2Size of the VM.

Best Practices

Further Resources