az-vm
Manage Azure Virtual Machines
TLDR
Display a table of available Virtual Machines
Create a virtual machine using the default Ubuntu image and generate SSH keys
Stop a Virtual Machine
Deallocate a Virtual Machine
Start a Virtual Machine
Restart a Virtual Machine
List VM images available in the Azure Marketplace
SYNOPSIS
az vm <SUBCOMMAND> [--help] [--output <FORMAT>] [--query <JMESPATH_QUERY>] [GLOBAL_OPTIONS]
PARAMETERS
<SUBCOMMAND>
Specifies the particular VM operation to perform. az vm offers many subcommands such as create (to deploy a new VM), list (to view existing VMs), show (to get details of a specific VM), delete (to remove a VM), start, stop, restart (to manage VM power state), update (to modify VM properties), resize (to change VM size), disk (to manage attached disks), and many more. Each subcommand has its own specific set of required and optional parameters.
--help
Displays detailed help information for the az vm command group or a specific subcommand when used with it (e.g., az vm create --help).
--output <FORMAT>
Configures the output format of the command. Common formats include json (the default), jsonc (colorized JSON), table (human-readable), tsv (tab-separated values), and yaml.
--query <JMESPATH_QUERY>
Uses a JMESPath query string to filter or transform the JSON output data, allowing users to extract specific information.
--verbose
Increases logging verbosity to show additional information, including debug logs.
--debug
Shows all debug logs for troubleshooting purposes.
--only-show-errors
Configures the command to only display errors and suppress warnings, useful for scripting.
--subscription <SUBSCRIPTION_ID_OR_NAME>
Overrides the currently active Azure subscription for the command execution, allowing management of resources across different subscriptions without switching contexts.
DESCRIPTION
az vm is a command group within the Azure CLI (Command-Line Interface) tool, specifically designed for comprehensive management of virtual machines (VMs) hosted on Microsoft Azure. It provides a robust and scriptable interface to perform various operations related to Azure VMs, ranging from deployment and configuration to monitoring and deletion.
Unlike a traditional Linux command that executes a single action, az vm acts as a parent command that encompasses a wide array of subcommands. Each subcommand is dedicated to a specific VM management task, allowing users to precisely control their Azure VM infrastructure without needing to navigate the Azure portal.
Key functionalities accessible through az vm subcommands include deploying new VMs from various pre-configured images (e.g., Ubuntu, Windows Server), listing existing VMs, viewing detailed properties, starting, stopping, restarting, resizing, and deleting VMs. It also supports more advanced operations like managing VM disks, extensions, and network configurations. The Azure CLI, including the az vm group, is cross-platform, running on Linux, macOS, and Windows, making it an indispensable tool for cloud administrators, DevOps engineers, and developers.
CAVEATS
The az vm command group requires the Azure CLI to be installed and properly configured on your system. Users must be authenticated to an Azure subscription (typically via az login) with sufficient permissions to manage virtual machines and associated resources (e.g., resource groups, virtual networks, storage accounts). Operations on Azure VMs can incur costs based on the VM size, uptime, storage, and network usage. Always verify resource group, location, and other parameters to prevent unintended resource creation or deletion. Some operations, particularly VM creation, can take several minutes to complete.
AUTHENTICATION REQUIREMENT
Before utilizing any az vm subcommand, you must first authenticate to your Azure subscription. This is typically done using the az login command. This command usually opens a web browser for interactive login, or it can be configured for non-interactive logins suitable for automation using service principals.
COMMON WORKFLOW EXAMPLE: CREATE A LINUX VM
A very common use case for az vm is creating a new virtual machine. Here's an example to create an Ubuntu VM:
az vm create \
--resource-group MyVmResourceGroup \
--name MyUbuntuVM \
--image UbuntuLTS \
--admin-username azureuser \
--generate-ssh-keys \
--location eastus \
--size Standard_B2s
This command deploys an Ubuntu LTS VM named 'MyUbuntuVM' in the 'eastus' region, within 'MyVmResourceGroup', using a specified username and generating SSH keys for authentication.
HISTORY
The Azure CLI, including the az vm command group, has evolved significantly as Microsoft's primary cross-platform command-line tool for Azure resource management. It replaced earlier iterations like the Node.js-based XPlat CLI, offering a more consistent and robust Python-based experience. The az vm command group quickly became a cornerstone of the CLI, providing granular control over Azure's core compute service. Its development has continuously focused on improving usability, adding support for new VM features (e.g., new VM sizes, confidential computing), and integrating seamlessly with other Azure services. It stands today as the go-to command-line tool for VM automation and scripting on Azure.
SEE ALSO
az login (authenticate to Azure), az group (manage Azure resource groups), az network (manage virtual networks, NICs, public IPs, and security groups), az storage (manage storage accounts and blobs), az disk (manage Azure managed disks), az aks (manage Azure Kubernetes Service clusters), gcloud compute (Google Cloud CLI for compute instances), aws ec2 (AWS CLI for EC2 instances)