What it does
az talks to Azure Resource Manager. You log in once (az login), choose a subscription, and work with resources inside resource groups. Every command follows the pattern az GROUP [SUBGROUP] VERB --options. Output is JSON by default; -o table is easier to read and --query (JMESPath) picks fields.
It is the main CLI tool for AZ-104 and for scripts and CI pipelines on Azure (with azure/login and OIDC in GitHub Actions).
How to write it
az GROUP [SUBGROUP] COMMAND [--options] [-o table|json|tsv] [--query EXPR]Main parts
Most used groups
login/logout/account- Sign in, choose the subscription.
group- Resource groups.
vm- Virtual machines.
networkvnet|nsg|public-ip|lb- Networking.
storageaccount|container|blob- Storage.
aks- Azure Kubernetes Service.
acr- Azure Container Registry.
keyvault- Key Vault (secrets, keys, certificates).
roleassignment/adsp- RBAC and service principals.
monitor- Metrics, logs, alerts, diagnostic settings.
policy- Azure Policy.
resource- Any resource by ID.
webapp/containerapp/functionapp- App platforms.
deploymentgroupcreate- Deploy Bicep or ARM templates.
upgrade/extension- Update the CLI / add extensions.
Options 8
Most used
Global options
Nothing matches this filter.
Examples 11
$ run as a normal user# run as root (or with sudo)
1Log in and choose a subscription
az login az account list -o table az account set --subscription "Lab Subscription" az account show --query "{name:name, id:id}" -o table2Create a resource group and a VM
az group create -n rg-lab-weu -l westeurope --tags owner=s0sta env=lab az vm create -g rg-lab-weu -n vm-web1 --image RedHat:RHEL:9-lvm-gen2:latest --size Standard_B2s --admin-username azureuser --ssh-key-values ~/.ssh/id_ed25519.pub --public-ip-sku Standard az vm list -g rg-lab-weu -d -o table3Stop paying for a lab VM
az vm deallocate -g rg-lab-weu -n vm-web1 az vm start -g rg-lab-weu -n vm-web14Network: VNet, subnet and NSG rule
az network vnet create -g rg-lab-weu -n vnet-lab --address-prefix 10.20.0.0/16 --subnet-name snet-web --subnet-prefix 10.20.1.0/24 az network nsg create -g rg-lab-weu -n nsg-web az network nsg rule create -g rg-lab-weu --nsg-name nsg-web -n allow-https --priority 100 --access Allow --protocol Tcp --destination-port-ranges 4435Storage account with no public blob access
az storage account create -g rg-lab-weu -n sts0stalab01 --sku Standard_LRS --min-tls-version TLS1_2 --allow-blob-public-access false az storage container create --account-name sts0stalab01 -n backups --auth-mode login6Key Vault and a secret
az keyvault create -g rg-lab-weu -n kv-s0sta-lab --enable-rbac-authorization true az keyvault secret set --vault-name kv-s0sta-lab -n db-password --value "$(openssl rand -base64 24)" az keyvault secret show --vault-name kv-s0sta-lab -n db-password --query value -o tsv7Create AKS and get the kubeconfig
az aks create -g rg-lab-weu -n aks-lab --node-count 2 --node-vm-size Standard_B2s --enable-managed-identity --network-plugin azure --generate-ssh-keys az aks get-credentials -g rg-lab-weu -n aks-lab kubectl get nodes8Give least-privilege access (RBAC)
az role assignment create --assignee user@example.com --role "Reader" --scope /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-lab-weu az role assignment list -g rg-lab-weu -o table9Find resources with a query
az resource list --tag env=lab --query "[].{name:name, type:type}" -o table az vm list --query "[?powerState=='VM running'].name" -d -o tsv10Deploy a Bicep file
az deployment group create -g rg-lab-weu -f main.bicep -p env=lab az deployment group what-if -g rg-lab-weu -f main.bicep11Clean up the whole lab
az group delete -n rg-lab-weu --yes --no-wait
Nothing matches this filter.
Watch out
az group deletedeletes everything inside; check the name twice.- Prefer managed identities and OIDC over client secrets for scripts and CI.
- Set budgets and alerts (
az consumption budget) on lab subscriptions.
Files
~/.azure/- Login tokens and CLI config (keep private).
Tips to remember
az interactivegives autocomplete;az find "create vm"shows examples.az config set defaults.group=rg-lab-weu defaults.location=westeuropesaves typing.
Exit codes
0 | Success. |
1 | Error. |
2 | Parser error (bad arguments). |
3 | Resource not found (some show commands). |