Azure Cost Optimization Skill
Analyze Azure subscriptions to identify cost savings through orphaned resource cleanup, rightsizing, and optimization recommendations based on actual usage data. This runbook guides an agent through discovering resources, querying actual cost data from the…
13 steps · start to finish.
- 1Step 1
Environment Setup
▶Verify all required tools, permissions, and inputs are available before proceeding.
echo "=== ENVIRONMENT SETUP ===" # Verify az CLI az --version || { echo "ERROR: Azure CLI not installed"; exit 1; } # Verify azqr azqr version || { echo "ERROR: Azure Quick Review (azqr) not installed"; exit 1; } # Verify az extensions az extension show --name costmanagement || az extension add --name costmanagement az extension show --name resource-graph || az extension add --name resource-graph # Verify authentication az account show || { echo "ERROR: Not authenticated — run 'az login'"; exit 1; } # Show subscription context az account list --output table # Create output directory mkdir -p /app/results echo "=== SETUP COMPLETE ==="Prompt the user for:
- SUBSCRIPTION_ID (required): the Azure subscription to analyze
- RESOURCE_GROUP (optional): leave blank for subscription-wide analysis
- ANALYSIS_SCOPE (optional, default:
subscription): narrow toredis-onlyoraks-onlyif the user specifies
- 2Step 2
Validate Prerequisites
▶SUBSCRIPTION_ID="<SUBSCRIPTION_ID>" RESOURCE_GROUP="<RESOURCE_GROUP>" # leave empty for subscription-wide
- 3Step 3
Conditional — Redis-Specific Analysis
▶Skip this step unless the user specifically asks about Redis, Azure Cache for Redis, or Azure Managed Redis optimization.
- 4Step 4
Conditional — AKS-Specific Analysis
▶Skip this step unless the user mentions AKS, Kubernetes, cluster, node pool, pod, or kubectl.
- 5Step 5
Load Best Practices
▶Load Azure cost optimization best practices to inform recommendations:
- 6Step 6
Run Azure Quick Review
▶Run azqr to identify orphaned resources eligible for immediate deletion:
- 7Step 7
Discover Resources
▶Use Azure Resource Graph for efficient cross-subscription resource discovery:
- 8Step 8
Query Actual Costs
▶Get actual cost data from Azure Cost Management API (last 30 days):
- 9Step 9
Validate Pricing
▶Fetch current pricing from official Azure pricing pages for the top resources identified in Step 8:
- 10Step 10
Collect Utilization Metrics
▶Query Azure Monitor for utilization data (last 14 days) to support rightsizing recommendations:
- 11Step 11
Iterate on Errors (max 3 rounds)
▶If any step above returns an error or incomplete data:
- 12Step 12
Generate Optimization Report
▶Create a comprehensive cost optimization report at /app/results/cost-optimization-report.md:
- 13Step 13
Final Checklist (MANDATORY — do not skip)
▶echo "=== FINAL OUTPUT VERIFICATION ===" RESULTS_DIR="/app/results" for f in \ "$RESULTS_DIR/cost-optimization-report.md" \