Skip to content

Azure — alert when approaching a subscription quota

An Azure subscription approaches a quota (vCPU per region, public IPs, storage accounts) — the next terraform apply fails with 429/ItemNotFound. Quota raises go via a support ticket, you need a head start.

Recipe

bash
#!/usr/bin/env bash
# /etc/cron.d/az-quota
# 0 */6 * * * root /opt/az-quota.sh

REGION=${REGION:-westeurope}
WARN_PCT=${WARN_PCT:-80}

# Compute quota only — extend with network/storage as needed
HOTSPOTS=$(az vm list-usage --location "$REGION" -o json \
  | jq --argjson w "$WARN_PCT" '
      [.[] | select(.limit > 0 and (.currentValue / .limit * 100) > $w) |
       {name: .localName.value, used: .currentValue, limit: .limit,
        pct: ((.currentValue / .limit * 100) | floor)}]')

COUNT=$(echo "$HOTSPOTS" | jq 'length')

if [ "${COUNT:-0}" -gt 0 ]; then
  SUMMARY=$(echo "$HOTSPOTS" | jq -r '.[] | "\(.name)=\(.pct)%"' | head -5 | tr '\n' ',')
  curl -fsS "$HEARTBEAT_URL" --data-urlencode "quota_warn=$COUNT,examples=$SUMMARY"
  exit 2
fi
echo "OK (no quotas above ${WARN_PCT}%)"

Same thing in Enterno.io

Wire to an Enterno heartbeat — catch 80 % quota a week or two before the hard stop, with time to open the Azure ticket.

Set up API monitor → ← All recipes

Related recipes