Azure | Virtual Machines | Tutorials
This tutorial will guide you through the process of deploying and managing Azure Virtual Machines (VMs) using Azure Resource Manager (ARM) templates. ARM templates are JSON files that define the infrastructure and configuration for your Azure solutions.
ARM templates provide a declarative way to define your Azure infrastructure. Instead of imperative steps (like scripts), you declare what you want to deploy, and the Azure Resource Manager service handles the deployment.
Before you begin, ensure you have the following:
Let's start by deploying a simple Windows VM. We'll use a predefined ARM template for this.
A typical ARM template consists of the following sections:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"vmName": {
"type": "string",
"defaultValue": "myVM",
"metadata": {
"description": "Name of the virtual machine."
}
},
"adminUsername": {
"type": "string",
"defaultValue": "azureuser",
"metadata": {
"description": "Username for the administrator account."
}
},
"adminPassword": {
"type": "securestring",
"metadata": {
"description": "Password for the administrator account."
}
},
"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'))]"
}
]
}
}
},
{
"type": "Microsoft.Network/virtualNetworks",
"apiVersion": "2020-07-01",
"name": "[concat(parameters('vmName'), '-vnet')]",
"location": "[resourceGroup().location]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"10.0.0.0/16"
]
}
}
},
{
"type": "Microsoft.Network/virtualNetworks/subnets",
"apiVersion": "2020-07-01",
"name": "[concat(parameters('vmName'), '-subnet')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Network/virtualNetworks', concat(parameters('vmName'), '-vnet'))]"
],
"properties": {
"addressPrefix": "10.0.0.0/24"
}
},
{
"type": "Microsoft.Network/networkInterfaces",
"apiVersion": "2020-07-01",
"name": "[concat(parameters('vmName'), '-nic')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[resourceId('Microsoft.Network/virtualNetworks/subnets', concat(parameters('vmName'), '-vnet'), concat(parameters('vmName'), '-subnet'))]"
],
"properties": {
"ipConfigurations": [
{
"name": "ipconfig1",
"properties": {
"subnet": {
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', concat(parameters('vmName'), '-vnet'), concat(parameters('vmName'), '-subnet'))]"
},
"privateIPAllocationMethod": "Dynamic"
}
}
]
}
}
],
"outputs": {
"vmId": {
"type": "string",
"value": "[resourceId('Microsoft.Compute/virtualMachines', parameters('vmName'))]"
}
}
}
azuredeploy.json.az group create --name myResourceGroup --location eastusaz deployment group create --resource-group myResourceGroup --template-file azuredeploy.json --parameters adminPassword='YourSecurePasswordHere'ARM templates can define more complex VM setups:
Ensure your VMs are highly available by distributing them across fault and update domains.
Learn More →Use high-performance managed disks for your VM's operating system and data.
Learn More →ARM templates are not just for initial deployment. You can also use them to:
You can re-run a deployment with an updated template to manage the state of your existing resources.
Ready to build more sophisticated Azure infrastructure? Explore these resources:
Explore ARM Template Functions Learn about Bicep Azure VM Best Practices