Azure

Virtual Machines (VM) – Reference

Azure Virtual Machines provide scalable, on-demand computing resources with support for Windows, Linux, and custom images.

On this page Overview Pricing VM Sizes Deployment Options REST API Code Samples

Overview

Azure VMs are available in a wide range of configurations suitable for general purpose, compute‑intensive, memory‑optimized, and GPU workloads. They can be managed through the Azure portal, Azure CLI, PowerShell, or REST API.

Pricing

Pricing is based on VM size, operating system, and region. You can use the Azure Pricing Calculator to estimate costs.

VM Sizes

Common families include:

Deployment Options

Azure CLI
az vm create \
  --resource-group MyResourceGroup \
  --name MyVM \
  --image UbuntuLTS \
  --admin-username azureuser \
  --generate-ssh-keys
                    
PowerShell
New-AzVm `
  -ResourceGroupName "MyResourceGroup" `
  -Name "MyVM" `
  -Location "EastUS" `
  -VirtualNetworkName "MyVnet" `
  -SubnetName "MySubnet" `
  -Image "Win2019Datacenter" `
  -Size "Standard_D2s_v3"
                    
ARM Template
{
  "$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": "myVM",
      "location": "[resourceGroup().location]",
      "properties": {
        "hardwareProfile": { "vmSize": "Standard_B2s" },
        "storageProfile": {
          "imageReference": {
            "publisher": "Canonical",
            "offer": "UbuntuServer",
            "sku": "20_04-lts-gen2",
            "version": "latest"
          },
          "osDisk": { "createOption": "FromImage" }
        },
        "osProfile": {
          "computerName": "myVM",
          "adminUsername": "azureuser",
          "linuxConfiguration": { "disablePasswordAuthentication": true }
        },
        "networkProfile": {
          "networkInterfaces": [
            {
              "id": "[resourceId('Microsoft.Network/networkInterfaces', 'myNic')]"
            }
          ]
        }
      }
    }
  ]
}
                    

REST API

Base URL: https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}?api-version=2022-08-01

Example: Get VM details

GET https://management.azure.com/subscriptions/xxxx/resourceGroups/MyRG/providers/Microsoft.Compute/virtualMachines/MyVM?api-version=2022-08-01
Authorization: Bearer <access_token>
        

Code Samples

Python (Azure SDK)

from azure.identity import DefaultAzureCredential
from azure.mgmt.compute import ComputeManagementClient

credential = DefaultAzureCredential()
subscription_id = "YOUR_SUBSCRIPTION_ID"
compute_client = ComputeManagementClient(credential, subscription_id)

vm = compute_client.virtual_machines.get("MyResourceGroup", "MyVM")
print(f"VM ID: {vm.id}")