Skill v1.0.1
currentAutomated scan100/1003 files
version: "1.0.1" name: az description: Use az CLI for Azure cloud resource management, Azure DevOps operations, VMs, storage, networking, AKS, and Key Vault with comprehensive authentication and output control.
Azure CLI (az) Skill
You are an Azure CLI specialist. This skill provides comprehensive guidance for managing Azure resources, Azure DevOps, and cloud infrastructure using the az command-line tool.
Core Principles
Authentication
Always ensure proper authentication before running Azure commands:
- Use
az loginfor interactive authentication - Use
az account showto verify current subscription - Use
az account setto switch subscriptions - Service principal authentication for automation
Output Formats
Azure CLI supports multiple output formats:
--output table- Human-readable table (default for many commands)--output json- Full JSON output for scripting--output tsv- Tab-separated values for parsing--output yaml- YAML format--output jsonc- Colorized JSON-o- Short form for--output
Query and Filtering
Use JMESPath queries with --query to filter results:
az vm list --query "[?location=='eastus'].name" -o tableaz resource list --query "[?type=='Microsoft.Compute/virtualMachines']"
Authentication and Account Management
Login and Authentication
# Interactive loginaz login# Login with specific tenantaz login --tenant <tenant-id># Login with service principalaz login --service-principal -u <app-id> -p <password-or-cert> --tenant <tenant-id># Login with managed identityaz login --identity# Check authentication statusaz account show# List all accessible subscriptionsaz account list -o table
Subscription Management
# Show current subscriptionaz account show# List all subscriptionsaz account list -o table# Set active subscriptionaz account set --subscription <subscription-id-or-name># Show subscription detailsaz account show --query "{SubscriptionName:name, SubscriptionId:id, TenantId:tenantId}"
Service Principal Management
# Create service principalaz ad sp create-for-rbac --name <name># Create with specific roleaz ad sp create-for-rbac --name <name> --role contributor --scopes /subscriptions/<subscription-id># List service principalsaz ad sp list --display-name <name># Delete service principalaz ad sp delete --id <app-id># Reset credentialsaz ad sp credential reset --id <app-id>
Resource Management
Resource Groups
# List resource groupsaz group list -o table# Create resource groupaz group create --name <name> --location <location># Show resource groupaz group show --name <name># Delete resource groupaz group delete --name <name> --yes --no-wait# Update tagsaz group update --name <name> --tags Environment=Dev Project=MyApp# List resources in groupaz resource list --resource-group <name> -o table# Export resource group templateaz group export --name <name>
Generic Resource Operations
# List all resourcesaz resource list -o table# List resources by typeaz resource list --resource-type Microsoft.Compute/virtualMachines -o table# Show resourceaz resource show --ids <resource-id>az resource show --resource-group <group> --name <name> --resource-type <type># Update resource tagsaz resource tag --tags Environment=Prod --ids <resource-id># Delete resourceaz resource delete --ids <resource-id># Move resourcesaz resource move --destination-group <dest-group> --ids <resource-id1> <resource-id2>
Locations and Providers
# List available locationsaz account list-locations -o table# List resource providersaz provider list -o table# Show provideraz provider show --namespace Microsoft.Compute# Register provideraz provider register --namespace Microsoft.Compute# Check registration statusaz provider show --namespace Microsoft.Compute --query "registrationState"
Azure DevOps
DevOps Configuration
# Configure default organization and projectaz devops configure --defaults organization=https://dev.azure.com/myorg project=MyProject# Show current defaultsaz devops configure --list# Login to Azure DevOpsaz devops login --organization https://dev.azure.com/myorg
Projects
# List projectsaz devops project list --organization https://dev.azure.com/myorg -o table# Create projectaz devops project create --name <name># Show projectaz devops project show --project <name># Delete projectaz devops project delete --id <project-id> --yes
Repositories
# List repositoriesaz repos list --organization https://dev.azure.com/myorg --project <project> -o table# Show repositoryaz repos show --repository <repo-name># Create repositoryaz repos create --name <name> --project <project># Delete repositoryaz repos delete --id <repo-id> --yes# Import repositoryaz repos import create --git-source-url <url> --repository <repo-name># List branchesaz repos ref list --repository <repo-name># List pull requestsaz repos pr list --repository <repo-name> -o table
Pipelines
# List pipelinesaz pipelines list --organization https://dev.azure.com/myorg --project <project> -o table# Show pipelineaz pipelines show --name <pipeline-name># Run pipelineaz pipelines run --name <pipeline-name># List pipeline runsaz pipelines runs list -o table# Show run detailsaz pipelines runs show --id <run-id># List build definitionsaz pipelines build list -o table# Queue buildaz pipelines build queue --definition-name <name>
Virtual Machines
VM Management
# List VMsaz vm list -o tableaz vm list --resource-group <group> -o table# Show VMaz vm show --resource-group <group> --name <vm-name># Create VM (basic)az vm create \--resource-group <group> \--name <vm-name> \--image Ubuntu2204 \--admin-username azureuser \--generate-ssh-keys# Create VM (detailed)az vm create \--resource-group <group> \--name <vm-name> \--image Ubuntu2204 \--size Standard_DS2_v2 \--admin-username azureuser \--ssh-key-values @~/.ssh/id_rsa.pub \--vnet-name myVnet \--subnet mySubnet \--public-ip-address myPublicIP \--nsg myNSG# Start VMaz vm start --resource-group <group> --name <vm-name># Stop VM (deallocate)az vm deallocate --resource-group <group> --name <vm-name># Stop VM (without deallocate)az vm stop --resource-group <group> --name <vm-name># Restart VMaz vm restart --resource-group <group> --name <vm-name># Delete VMaz vm delete --resource-group <group> --name <vm-name> --yes# Resize VMaz vm resize --resource-group <group> --name <vm-name> --size Standard_DS3_v2# List available sizesaz vm list-sizes --location eastus -o table
VM Images
# List popular imagesaz vm image list -o table# List all images from publisheraz vm image list --publisher Canonical --all -o table# Show image detailsaz vm image show --urn Canonical:Ubuntu2204:latest# List VM SKUsaz vm list-skus --location eastus --size Standard_D -o table
VM Extensions
# List extensions on VMaz vm extension list --resource-group <group> --vm-name <vm-name># Install extensionaz vm extension set \--resource-group <group> \--vm-name <vm-name> \--name customScript \--publisher Microsoft.Azure.Extensions# Delete extensionaz vm extension delete --resource-group <group> --vm-name <vm-name> --name <extension-name>
Storage
Storage Accounts
# List storage accountsaz storage account list -o table# Create storage accountaz storage account create \--name <account-name> \--resource-group <group> \--location eastus \--sku Standard_LRS# Show storage accountaz storage account show --name <account-name># Get connection stringaz storage account show-connection-string --name <account-name># Get access keysaz storage account keys list --account-name <account-name># Delete storage accountaz storage account delete --name <account-name> --yes
Blob Storage
# List containersaz storage container list --account-name <account-name> -o table# Create containeraz storage container create --name <container-name> --account-name <account-name># Upload blobaz storage blob upload \--account-name <account-name> \--container-name <container-name> \--name <blob-name> \--file <local-file-path># Download blobaz storage blob download \--account-name <account-name> \--container-name <container-name> \--name <blob-name> \--file <local-file-path># List blobsaz storage blob list --account-name <account-name> --container-name <container-name> -o table# Delete blobaz storage blob delete --account-name <account-name> --container-name <container-name> --name <blob-name># Copy blobaz storage blob copy start \--account-name <dest-account> \--destination-container <dest-container> \--destination-blob <dest-blob> \--source-uri <source-blob-url>
Networking
Virtual Networks
# List vnetsaz network vnet list -o table# Create vnetaz network vnet create \--resource-group <group> \--name <vnet-name> \--address-prefix 10.0.0.0/16 \--subnet-name <subnet-name> \--subnet-prefix 10.0.1.0/24# Show vnetaz network vnet show --resource-group <group> --name <vnet-name># Delete vnetaz network vnet delete --resource-group <group> --name <vnet-name># List subnetsaz network vnet subnet list --resource-group <group> --vnet-name <vnet-name> -o table# Create subnetaz network vnet subnet create \--resource-group <group> \--vnet-name <vnet-name> \--name <subnet-name> \--address-prefix 10.0.2.0/24
Network Security Groups (NSGs)
# List NSGsaz network nsg list -o table# Create NSGaz network nsg create --resource-group <group> --name <nsg-name># List NSG rulesaz network nsg rule list --resource-group <group> --nsg-name <nsg-name> -o table# Create NSG ruleaz network nsg rule create \--resource-group <group> \--nsg-name <nsg-name> \--name <rule-name> \--priority 100 \--source-address-prefixes '*' \--source-port-ranges '*' \--destination-address-prefixes '*' \--destination-port-ranges 80 \--access Allow \--protocol Tcp \--description "Allow HTTP"# Delete NSG ruleaz network nsg rule delete --resource-group <group> --nsg-name <nsg-name> --name <rule-name>
Public IPs and Load Balancers
# List public IPsaz network public-ip list -o table# Create public IPaz network public-ip create --resource-group <group> --name <ip-name># Show public IP addressaz network public-ip show --resource-group <group> --name <ip-name> --query "ipAddress"# List load balancersaz network lb list -o table# Create load balanceraz network lb create \--resource-group <group> \--name <lb-name> \--sku Standard \--public-ip-address <ip-name>
App Services
Web Apps
# List app service plansaz appservice plan list -o table# Create app service planaz appservice plan create \--name <plan-name> \--resource-group <group> \--sku B1 \--is-linux# List web appsaz webapp list -o table# Create web appaz webapp create \--resource-group <group> \--plan <plan-name> \--name <app-name> \--runtime "NODE:18-lts"# Show web appaz webapp show --resource-group <group> --name <app-name># Deploy from Gitaz webapp deployment source config \--name <app-name> \--resource-group <group> \--repo-url <git-url> \--branch main \--manual-integration# Deploy ZIP fileaz webapp deployment source config-zip \--resource-group <group> \--name <app-name> \--src <zip-file-path># Start/stop/restart web appaz webapp start --resource-group <group> --name <app-name>az webapp stop --resource-group <group> --name <app-name>az webapp restart --resource-group <group> --name <app-name># View logsaz webapp log tail --resource-group <group> --name <app-name># Delete web appaz webapp delete --resource-group <group> --name <app-name>
App Settings and Configuration
# List app settingsaz webapp config appsettings list --name <app-name> --resource-group <group># Set app settingsaz webapp config appsettings set \--name <app-name> \--resource-group <group> \--settings KEY1=value1 KEY2=value2# Delete app settingaz webapp config appsettings delete \--name <app-name> \--resource-group <group> \--setting-names KEY1# Set connection stringsaz webapp config connection-string set \--name <app-name> \--resource-group <group> \--connection-string-type SQLAzure \--settings DefaultConnection="connection-string-value"
Container Services (AKS)
AKS Cluster Management
# List AKS clustersaz aks list -o table# Create AKS clusteraz aks create \--resource-group <group> \--name <cluster-name> \--node-count 3 \--enable-addons monitoring \--generate-ssh-keys# Get AKS credentialsaz aks get-credentials --resource-group <group> --name <cluster-name># Show AKS clusteraz aks show --resource-group <group> --name <cluster-name># Scale AKS clusteraz aks scale --resource-group <group> --name <cluster-name> --node-count 5# Upgrade AKS clusteraz aks upgrade --resource-group <group> --name <cluster-name> --kubernetes-version 1.28.0# Stop AKS clusteraz aks stop --resource-group <group> --name <cluster-name># Start AKS clusteraz aks start --resource-group <group> --name <cluster-name># Delete AKS clusteraz aks delete --resource-group <group> --name <cluster-name> --yes
Container Registry (ACR)
# List container registriesaz acr list -o table# Create container registryaz acr create --resource-group <group> --name <registry-name> --sku Basic# Login to registryaz acr login --name <registry-name># List repositoriesaz acr repository list --name <registry-name> -o table# Show repository tagsaz acr repository show-tags --name <registry-name> --repository <repo-name># Delete imageaz acr repository delete --name <registry-name> --image <repo-name>:<tag> --yes# Import imageaz acr import \--name <registry-name> \--source docker.io/library/nginx:latest \--image nginx:latest
Databases
SQL Databases
# List SQL serversaz sql server list -o table# Create SQL serveraz sql server create \--name <server-name> \--resource-group <group> \--location eastus \--admin-user <admin-user> \--admin-password <admin-password># List databasesaz sql db list --resource-group <group> --server <server-name> -o table# Create databaseaz sql db create \--resource-group <group> \--server <server-name> \--name <db-name> \--service-objective S0# Show connection stringaz sql db show-connection-string \--client ado.net \--name <db-name> \--server <server-name># Configure firewall ruleaz sql server firewall-rule create \--resource-group <group> \--server <server-name> \--name AllowMyIP \--start-ip-address <ip> \--end-ip-address <ip>
Cosmos DB
# List Cosmos DB accountsaz cosmosdb list -o table# Create Cosmos DB accountaz cosmosdb create \--name <account-name> \--resource-group <group> \--kind GlobalDocumentDB# List databasesaz cosmosdb sql database list \--account-name <account-name> \--resource-group <group># Create databaseaz cosmosdb sql database create \--account-name <account-name> \--resource-group <group> \--name <db-name># Get connection stringsaz cosmosdb keys list \--name <account-name> \--resource-group <group> \--type connection-strings
Monitoring and Logs
Activity Logs
# List activity logsaz monitor activity-log list -o table# List activity logs for resource groupaz monitor activity-log list --resource-group <group> -o table# List recent activity logsaz monitor activity-log list --start-time 2024-01-01T00:00:00Z -o table# Query specific operationsaz monitor activity-log list --filters "eventName eq 'Create or Update Virtual Machine'"
Metrics
# List available metricsaz monitor metrics list-definitions --resource <resource-id># Get metric valuesaz monitor metrics list \--resource <resource-id> \--metric "Percentage CPU" \--start-time 2024-01-01T00:00:00Z \--end-time 2024-01-02T00:00:00Z# List metric alertsaz monitor metrics alert list -o table# Create metric alertaz monitor metrics alert create \--name <alert-name> \--resource-group <group> \--scopes <resource-id> \--condition "avg Percentage CPU > 80" \--description "Alert when CPU exceeds 80%"
Log Analytics
# List workspacesaz monitor log-analytics workspace list -o table# Create workspaceaz monitor log-analytics workspace create \--resource-group <group> \--workspace-name <workspace-name># Query logsaz monitor log-analytics query \--workspace <workspace-id> \--analytics-query "AzureActivity | limit 10"# List tablesaz monitor log-analytics workspace table list \--resource-group <group> \--workspace-name <workspace-name>
Azure Functions
Function Apps
# List function appsaz functionapp list -o table# Create function appaz functionapp create \--resource-group <group> \--consumption-plan-location eastus \--runtime node \--runtime-version 18 \--functions-version 4 \--name <function-app-name> \--storage-account <storage-account-name># Deploy functionaz functionapp deployment source config-zip \--resource-group <group> \--name <function-app-name> \--src <zip-file-path># List functionsaz functionapp function list --resource-group <group> --name <function-app-name># Show functionaz functionapp function show \--resource-group <group> \--name <function-app-name> \--function-name <function-name># Start/stop function appaz functionapp start --resource-group <group> --name <function-app-name>az functionapp stop --resource-group <group> --name <function-app-name># View logsaz functionapp log tail --resource-group <group> --name <function-app-name>
Key Vault
Key Vault Management
# List key vaultsaz keyvault list -o table# Create key vaultaz keyvault create \--name <vault-name> \--resource-group <group> \--location eastus# Show key vaultaz keyvault show --name <vault-name># Delete key vaultaz keyvault delete --name <vault-name># Purge deleted vaultaz keyvault purge --name <vault-name>
Secrets Management
# List secretsaz keyvault secret list --vault-name <vault-name> -o table# Set secretaz keyvault secret set --vault-name <vault-name> --name <secret-name> --value <secret-value># Get secretaz keyvault secret show --vault-name <vault-name> --name <secret-name># Get secret value onlyaz keyvault secret show --vault-name <vault-name> --name <secret-name> --query "value" -o tsv# Delete secretaz keyvault secret delete --vault-name <vault-name> --name <secret-name># List secret versionsaz keyvault secret list-versions --vault-name <vault-name> --name <secret-name>
Keys and Certificates
# List keysaz keyvault key list --vault-name <vault-name> -o table# Create keyaz keyvault key create --vault-name <vault-name> --name <key-name> --protection software# List certificatesaz keyvault certificate list --vault-name <vault-name> -o table# Import certificateaz keyvault certificate import \--vault-name <vault-name> \--name <cert-name> \--file <cert-file-path>
Role-Based Access Control (RBAC)
Role Assignments
# List role assignmentsaz role assignment list -o table# List role assignments for resource groupaz role assignment list --resource-group <group> -o table# Create role assignmentaz role assignment create \--assignee <user-email-or-sp-id> \--role "Contributor" \--scope /subscriptions/<subscription-id>/resourceGroups/<group># Create role assignment for subscriptionaz role assignment create \--assignee <user-email-or-sp-id> \--role "Reader" \--subscription <subscription-id># Delete role assignmentaz role assignment delete \--assignee <user-email-or-sp-id> \--role "Contributor" \--resource-group <group>
Role Definitions
# List role definitionsaz role definition list -o table# List built-in rolesaz role definition list --query "[?type=='BuiltInRole'].{Name:roleName}" -o table# Show role definitionaz role definition list --name "Contributor"# Create custom roleaz role definition create --role-definition <json-file-path># Update custom roleaz role definition update --role-definition <json-file-path># Delete custom roleaz role definition delete --name <role-name>
Complete Workflows
Workflow 1: Deploy Web Application
# 1. Create resource groupaz group create --name myapp-rg --location eastus# 2. Create app service planaz appservice plan create --name myapp-plan --resource-group myapp-rg --sku B1 --is-linux# 3. Create web appaz webapp create --resource-group myapp-rg --plan myapp-plan --name myapp-webapp --runtime "NODE:18-lts"# 4. Configure app settingsaz webapp config appsettings set --name myapp-webapp --resource-group myapp-rg --settings NODE_ENV=production# 5. Deploy applicationaz webapp deployment source config-zip --resource-group myapp-rg --name myapp-webapp --src app.zip# 6. Verify deploymentaz webapp show --resource-group myapp-rg --name myapp-webapp --query "defaultHostName" -o tsv
Workflow 2: Create AKS Cluster with ACR
# 1. Create resource groupaz group create --name k8s-rg --location eastus# 2. Create container registryaz acr create --resource-group k8s-rg --name myacr --sku Basic# 3. Create AKS clusteraz aks create --resource-group k8s-rg --name myk8s --node-count 2 --generate-ssh-keys --attach-acr myacr# 4. Get cluster credentialsaz aks get-credentials --resource-group k8s-rg --name myk8s# 5. Verify clusterkubectl get nodes
Workflow 3: Mirror Azure DevOps Repository to GitHub
# 1. Set DevOps defaultsaz devops configure --defaults organization=https://dev.azure.com/myorg project=MyProject# 2. List repositoriesaz repos list -o table# 3. Get repository clone URLREPO_URL=$(az repos show --repository MyRepo --query "remoteUrl" -o tsv)# 4. Clone repository (mirror)git clone --mirror "$REPO_URL"# 5. Add GitHub remotecd MyRepo.gitgit remote add github git@github.com:myuser/myrepo.git# 6. Push to GitHubgit push --mirror github
Workflow 4: Setup Virtual Machine with Storage
# 1. Create resource groupaz group create --name vm-rg --location eastus# 2. Create storage accountaz storage account create --name vmstorage --resource-group vm-rg --sku Standard_LRS# 3. Create virtual networkaz network vnet create --resource-group vm-rg --name myVnet --subnet-name mySubnet# 4. Create public IPaz network public-ip create --resource-group vm-rg --name myPublicIP# 5. Create NSG with SSH ruleaz network nsg create --resource-group vm-rg --name myNSGaz network nsg rule create --resource-group vm-rg --nsg-name myNSG --name AllowSSH --priority 1000 --destination-port-ranges 22 --protocol Tcp --access Allow# 6. Create VMaz vm create \--resource-group vm-rg \--name myVM \--image Ubuntu2204 \--vnet-name myVnet \--subnet mySubnet \--public-ip-address myPublicIP \--nsg myNSG \--admin-username azureuser \--generate-ssh-keys# 7. Get public IP addressaz vm show --resource-group vm-rg --name myVM --show-details --query "publicIps" -o tsv
Workflow 5: Deploy Function App with Key Vault Integration
# 1. Create resource groupaz group create --name func-rg --location eastus# 2. Create storage account for functionaz storage account create --name funcstorage --resource-group func-rg --sku Standard_LRS# 3. Create Key Vaultaz keyvault create --name myfuncvault --resource-group func-rg --location eastus# 4. Add secret to Key Vaultaz keyvault secret set --vault-name myfuncvault --name DatabasePassword --value "SuperSecret123!"# 5. Create function appaz functionapp create \--resource-group func-rg \--consumption-plan-location eastus \--runtime node \--runtime-version 18 \--functions-version 4 \--name myfuncapp \--storage-account funcstorage# 6. Enable managed identity for function appaz functionapp identity assign --name myfuncapp --resource-group func-rg# 7. Get function app identityFUNC_IDENTITY=$(az functionapp identity show --name myfuncapp --resource-group func-rg --query "principalId" -o tsv)# 8. Grant function app access to Key Vaultaz keyvault set-policy --name myfuncvault --object-id $FUNC_IDENTITY --secret-permissions get list# 9. Configure function app to reference Key Vault secretaz functionapp config appsettings set \--name myfuncapp \--resource-group func-rg \--settings DatabasePassword="@Microsoft.KeyVault(SecretUri=https://myfuncvault.vault.azure.net/secrets/DatabasePassword/)"
Best Practices
Output and Querying
- Use appropriate output format for context:
--output tablefor human review--output jsonfor scripting and automation--output tsvfor simple parsing
- Master JMESPath queries:
- Filter results:
--query "[?location=='eastus']" - Select fields:
--query "[].{Name:name, Location:location}" - First element:
--query "[0]"
- Use --query with -o tsv for clean scripting:
``bash RESOURCE_ID=$(az resource show --name myapp --resource-group myrg --query "id" -o tsv) ``
Resource Management
- Tag resources consistently:
``bash az group create --name myrg --location eastus --tags Environment=Production Owner=TeamA CostCenter=12345 ``
- Use resource groups for lifecycle management:
- Group related resources together
- Delete entire environments by deleting resource group
- Check resource limits and quotas:
``bash az vm list-usage --location eastus -o table ``
Security
- Use managed identities when possible instead of service principals
- Store secrets in Key Vault instead of app settings
- Enable soft delete on Key Vaults for production
- Use Azure RBAC for fine-grained access control
- Regularly rotate credentials for service principals
Performance
- Use --no-wait for long-running operations:
``bash az vm create --resource-group myrg --name myvm --image Ubuntu2204 --no-wait ``
- Batch operations when possible:
``bash az vm start --ids $(az vm list -g myrg --query "[].id" -o tsv) ``
- Use parallel execution for multiple operations:
``bash # In shell scripts, use xargs or parallel az vm list --query "[].name" -o tsv | xargs -P 5 -I {} az vm start --name {} --resource-group myrg ``
Cost Management
- Stop/deallocate VMs when not in use:
``bash az vm deallocate --resource-group myrg --name myvm ``
- Use appropriate SKUs - don't over-provision
- Clean up unused resources regularly
- Set up budgets and alerts:
``bash az consumption budget list ``
Common Patterns
Pattern 1: List Resources with Custom Output
# List VMs with custom columnsaz vm list --query "[].{Name:name, ResourceGroup:resourceGroup, Location:location, PowerState:powerState}" -o table# List web apps with URLsaz webapp list --query "[].{Name:name, URL:defaultHostName, State:state}" -o table
Pattern 2: Bulk Operations
# Start all VMs in resource groupaz vm start --ids $(az vm list -g myrg --query "[].id" -o tsv)# Stop all VMs in subscriptionaz vm deallocate --ids $(az vm list --query "[].id" -o tsv)# Delete all resource groups with specific tagaz group list --tag Environment=Dev --query "[].name" -o tsv | xargs -I {} az group delete --name {} --yes --no-wait
Pattern 3: Resource Creation with Dependencies
# Create resources in order, capturing IDsVNET_ID=$(az network vnet create --name myVnet --resource-group myrg --query "newVNet.id" -o tsv)SUBNET_ID=$(az network vnet subnet create --name mySubnet --vnet-name myVnet --resource-group myrg --query "id" -o tsv)VM_ID=$(az vm create --name myVM --resource-group myrg --image Ubuntu2204 --subnet $SUBNET_ID --query "id" -o tsv)
Pattern 4: Configuration Backup
# Export resource group templateaz group export --name myrg > myrg-template.json# Export individual resourceaz resource show --ids <resource-id> > resource-config.json# Export all resource groupsaz group list --query "[].name" -o tsv | while read rg; doaz group export --name "$rg" > "${rg}-template.json"done
Pattern 5: Health Checks and Monitoring
# Check VM power stateaz vm get-instance-view --resource-group myrg --name myvm --query "instanceView.statuses[?starts_with(code, 'PowerState/')].displayStatus" -o tsv# Check web app statusaz webapp show --resource-group myrg --name myapp --query "state" -o tsv# Monitor activity log for errorsaz monitor activity-log list --start-time $(date -u -d '1 hour ago' '+%Y-%m-%dT%H:%M:%SZ') --query "[?level=='Error']" -o table
Troubleshooting
Issue: Authentication Failures
# Solution 1: Re-loginaz logoutaz login# Solution 2: Clear token cacherm -rf ~/.azure# Solution 3: Login with specific tenantaz login --tenant <tenant-id># Verify authenticationaz account show
Issue: Subscription Not Found
# List all accessible subscriptionsaz account list -o table# Set correct subscriptionaz account set --subscription <subscription-id># Verify current subscriptionaz account show --query "{Name:name, ID:id}" -o table
Issue: Resource Already Exists
# Check if resource existsaz resource show --name <resource-name> --resource-group <group> --resource-type <type># List resources with same nameaz resource list --name <resource-name> -o table# Use unique names or clean up existing resourcesaz resource delete --ids <resource-id>
Issue: Insufficient Permissions
# Check your role assignmentsaz role assignment list --assignee $(az account show --query "user.name" -o tsv) -o table# Check required permissions for operation# Azure documentation provides required permissions for each operation# Request access from administrator if needed
Issue: Quota or Limit Exceeded
# Check current usageaz vm list-usage --location eastus -o table# Request quota increase through Azure Portal or support ticket# Use different region if availableaz account list-locations -o table
Issue: Long-Running Operation Timeout
# Use --no-wait to avoid timeoutaz vm create --resource-group myrg --name myvm --image Ubuntu2204 --no-wait# Check operation statusaz vm show --resource-group myrg --name myvm --query "provisioningState"# Monitor with pollingwhile true; doSTATE=$(az vm show --resource-group myrg --name myvm --query "provisioningState" -o tsv 2>/dev/null)echo "Current state: $STATE"[[ "$STATE" == "Succeeded" ]] && breaksleep 10done
Quick Reference
# Authenticationaz loginaz account showaz account set --subscription <id># Resource Groupsaz group create --name <name> --location <location>az group list -o tableaz group delete --name <name> --yes# Virtual Machinesaz vm list -o tableaz vm create --resource-group <rg> --name <name> --image Ubuntu2204az vm start/stop/restart --resource-group <rg> --name <name># Storageaz storage account create --name <name> --resource-group <rg>az storage blob upload --account-name <account> --container <container> --name <blob> --file <file># Web Appsaz webapp create --resource-group <rg> --plan <plan> --name <name> --runtime "NODE:18-lts"az webapp deployment source config-zip --resource-group <rg> --name <name> --src <zip># Azure DevOpsaz repos list -o tableaz pipelines list -o tableaz pipelines run --name <pipeline># Networkingaz network vnet create --resource-group <rg> --name <vnet>az network nsg create --resource-group <rg> --name <nsg># Container Servicesaz aks create --resource-group <rg> --name <cluster>az aks get-credentials --resource-group <rg> --name <cluster>az acr create --resource-group <rg> --name <registry># Key Vaultaz keyvault create --name <vault> --resource-group <rg>az keyvault secret set --vault-name <vault> --name <secret> --value <value>az keyvault secret show --vault-name <vault> --name <secret> --query "value" -o tsv# Monitoringaz monitor activity-log list -o tableaz monitor metrics list --resource <id> --metric <metric># Useful query patterns--query "[].{Name:name, Location:location}" -o table--query "[?location=='eastus'].name" -o tsv--query "[0].id" -o tsv
Integration with Other Tools
Working with Git
After Azure DevOps repository operations, integrate with git workflow:
# Clone Azure DevOps repoREPO_URL=$(az repos show --repository MyRepo --query "remoteUrl" -o tsv)git clone "$REPO_URL"# Use git skill for commit and push operations
Working with Kubernetes
After AKS operations, use kubectl:
# Get credentialsaz aks get-credentials --resource-group myrg --name myk8s# Then use kubectlkubectl get nodeskubectl apply -f deployment.yaml
Working with Docker
After ACR operations, use docker:
# Login to ACRaz acr login --name myacr# Then use dockerdocker build -t myacr.azurecr.io/myapp:v1 .docker push myacr.azurecr.io/myapp:v1
Summary
Primary directives:
- Always authenticate before running commands
- Use appropriate output formats for context (table for humans, json/tsv for scripts)
- Master --query for filtering results
- Tag resources consistently for organization
- Use --no-wait for long operations to avoid timeouts
- Store secrets in Key Vault, not in app settings
- Use managed identities when possible
- Clean up resources to avoid unnecessary costs
Most common commands:
az login- Authenticateaz account set --subscription <id>- Set subscriptionaz group create/delete- Manage resource groupsaz <service> list -o table- List resourcesaz <service> show --query "<path>" -o tsv- Get specific valuesaz devops configure --defaults- Set DevOps defaultsaz repos list- List repositoriesaz pipelines run- Run pipelines