Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Check and manage Azure subscription quotas, usage limits, and request capacity increases
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/check-quota.sh
1#!/usr/bin/env bash2# check-quota.sh3# Checks Azure quota limits and current usage for a resource provider.4# Returns a table with limit, usage, and available capacity for every quota5# (or a single quota when resource-name is provided).6#7# Usage:8# ./check-quota.sh <resource-provider> <region> [resource-name] [subscription-id]9#10# Examples:11# ./check-quota.sh Microsoft.Compute eastus # All compute quotas with usage12# ./check-quota.sh Microsoft.Compute eastus standardDSv3Family # Single quota with usage1314set -euo pipefail1516RESOURCE_PROVIDER="${1:?Usage: $0 <resource-provider> <region> [resource-name] [subscription-id]}"17REGION="${2:?Usage: $0 <resource-provider> <region> [resource-name] [subscription-id]}"18RESOURCE_NAME="${3:-}"19SUBSCRIPTION_ID="${4:-}"2021# Ensure the quota extension is installed22if ! az extension list --query "[?name=='quota'].name" -o tsv 2>/dev/null | grep -q quota; then23echo "Installing quota extension..."24az extension add --name quota --yes 2>/dev/null25fi2627# Resolve subscription28if [ -z "$SUBSCRIPTION_ID" ]; then29SUBSCRIPTION_ID=$(az account show --query id -o tsv)30fi3132SCOPE="/subscriptions/$SUBSCRIPTION_ID/providers/$RESOURCE_PROVIDER/locations/$REGION"3334echo "Checking quotas in scope $SCOPE"3536if [ -n "$RESOURCE_NAME" ]; then37# Single-resource mode38echo "Quota for '$RESOURCE_NAME' ($RESOURCE_PROVIDER, $REGION):"39echo ""4041LIMIT=$(az quota show \42--resource-name "$RESOURCE_NAME" \43--scope "$SCOPE" \44--query "properties.limit.value" -o tsv)4546USAGE=$(az quota usage show \47--resource-name "$RESOURCE_NAME" \48--scope "$SCOPE" \49--query "properties.usages.value" -o tsv)5051AVAILABLE=$((LIMIT - USAGE))5253printf "%-30s %-10s %-10s %-10s %-10s\n" "Resource" "Region" "Limit" "Usage" "Available"54printf "%-30s %-10s %-10s %-10s %-10s\n" "--------" "------" "-----" "-----" "---------"55printf "%-30s %-10s %-10s %-10s %-10s\n" "$RESOURCE_NAME" "$REGION" "$LIMIT" "$USAGE" "$AVAILABLE"56else57# All-quotas mode: fetch limits and usage, join by name58echo "Quotas for $RESOURCE_PROVIDER in $REGION:"59echo ""6061QUOTAS_JSON=$(az quota list --scope "$SCOPE" -o json 2>/dev/null)62USAGES_JSON=$(az quota usage list --scope "$SCOPE" -o json 2>/dev/null)6364printf "%-40s %-10s %-10s %-10s %-10s\n" "Resource" "Region" "Limit" "Usage" "Available"65printf "%-40s %-10s %-10s %-10s %-10s\n" "--------" "------" "-----" "-----" "---------"6667echo "$QUOTAS_JSON" | python3 -c "68import json, sys6970quotas = json.load(sys.stdin)71usages = json.loads('''$USAGES_JSON''')7273usage_lookup = {}74for u in usages:75usage_lookup[u['name']] = u.get('properties', {}).get('usages', {}).get('value', 0)7677for q in quotas:78name = q['name']79limit = q.get('properties', {}).get('limit', {}).get('value', 0)80used = usage_lookup.get(name, 0)81avail = limit - used82print(f'{name:<40} $REGION{\"\":<4} {limit:<10} {used:<10} {avail:<10}')83"84fi85