cheat-sheets

Azure CLI (az)

The Azure CLI manages Microsoft Azure resources from the terminal. Compare AWS CLI and gcloud (Google Cloud CLI); for provisioning as code see Terraform.

Documentation: Azure CLI docs


Install #

PLATFORMCOMMAND
Debian / Ubuntucurl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
macOSbrew install azure-cli (Homebrew)
Windowswinget install Microsoft.AzureCLI or choco install azure-cli (Chocolatey)
Containerdocker run -it mcr.microsoft.com/azure-cli (Docker)

az upgrade updates the CLI. az version shows versions.

Sign In and Subscriptions #

COMMANDDESCRIPTION
az loginBrowser sign-in
az login --use-device-codeSign in on a headless machine
az login --service-principal -u <APP-ID> -p <SECRET> --tenant <TENANT>Service principal (automation)
az account list -o tableList subscriptions
az account set --subscription "<NAME-OR-ID>"Choose the active subscription
az account showCurrent subscription
az logoutSign out

Resource Groups #

COMMANDDESCRIPTION
az group create -n myrg -l westeuropeCreate
az group list -o tableList
az group delete -n myrg --yes --no-waitDelete a group and everything in it
az resource list -g myrg -o tableResources in a group

Virtual Machines #

COMMANDDESCRIPTION
az vm image list -o tableCommon images
az vm list-sizes -l westeurope -o tableSizes in a region
az vm create -g myrg -n myvm --image Ubuntu2204 --size Standard_B2s --admin-username azureuser --generate-ssh-keysCreate a Linux VM
az vm list -g myrg -d -o tableList with power state and IPs
az vm start|stop|deallocate|restart -g myrg -n myvmPower actions (use deallocate to stop billing for compute)
az vm open-port -g myrg -n myvm --port 80Open a port in the NSG
az vm delete -g myrg -n myvm --yesDelete

Kubernetes (AKS) and Registry #

COMMANDDESCRIPTION
az aks create -g myrg -n myaks --node-count 2 --generate-ssh-keysCreate a cluster
az aks get-credentials -g myrg -n myaksAdd to kubeconfig (see Kubectl)
az aks list -o tableList clusters
az aks scale -g myrg -n myaks --node-count 3Scale
az aks delete -g myrg -n myaks --yes --no-waitDelete
az acr create -g myrg -n myregistry --sku BasicCreate a container registry
az acr login -n myregistryLog Docker in to it

Storage #

COMMANDDESCRIPTION
az storage account create -g myrg -n mystorageacct --sku Standard_LRSCreate (name is globally unique, lowercase)
az storage container create --account-name mystorageacct -n data --auth-mode loginCreate a blob container
az storage blob upload --account-name mystorageacct -c data -f ./file -n file --auth-mode loginUpload
az storage blob list --account-name mystorageacct -c data --auth-mode login -o tableList

Identity and Access #

COMMANDDESCRIPTION
az ad sp create-for-rbac --name myapp --role Contributor --scopes /subscriptions/<SUB>/resourceGroups/myrgService principal limited to one group
az role assignment create --assignee <ID> --role Reader --scope <SCOPE>Grant a role
az role assignment list --assignee <ID> -o tableList roles
az keyvault secret show --vault-name myvault -n mysecret --query value -o tsvRead a secret

Output and Querying #

OPTIONDESCRIPTION
-o table / -o json / -o tsv / -o yamlOutput format (tsv is good for scripts)
--query "[].{Name:name, Size:hardwareProfile.vmSize}"JMESPath filter
--query "[?location=='westeurope'].name" -o tsvFilter rows
az config set defaults.group=myrg defaults.location=westeuropeDefault group and location
az find "az vm create"Example commands
az <group> --helpHelp for any command group

Not Verified #

Written from knowledge of the CLI and not run against a subscription. Check az <command> --help, as parameter names and image aliases change.

Search all sheets

Tip: / or Ctrl/Cmd+K to open, Esc to close.