Home / Market / az cost optimize

az cost optimize

Analyze Azure resources used in the app (IaC files and/or resources in a target rg) and optimize costs - creating GitHub issues for identified optimizations.

skill★ 417948672 dlskills.shMITInstall in CosmosUpstream Source

Documentation & Preview

--- name: az-cost-optimize description: 'Analyze Azure resources used in the app (IaC files and/or resources in a target rg) and optimize costs - creating GitHub issues for identified optimizations.'

---

Azure Cost Optimize

This workflow analyzes Infrastructure-as-Code (IaC) files and Azure resources to generate cost optimization recommendations. It creates individual GitHub issues for each optimization opportunity plus one EPIC issue to coordinate implementation, enabling efficient tracking and execution of cost savings initiatives.

Prerequisites

Workflow Steps

Step 1: Get Azure Best Practices

Action: Retrieve cost optimization best practices before analysis

Tools: Azure MCP best practices tool

Process:

  1. Load Best Practices:

Step 2: Discover Azure Infrastructure

Action: Dynamically discover and analyze Azure resources and configurations

Tools: Azure MCP tools + Azure CLI fallback + Local file system access

Process:

  1. Resource Discovery:
  1. IaC Detection:
  1. Configuration Analysis:

Step 3: Collect Usage Metrics & Validate Current Costs

Action: Gather utilization data AND verify actual resource costs

Tools: Azure MCP monitoring tools + Azure CLI

Process:

  1. Find Monitoring Sources:
  1. Execute Usage Queries:
   // CPU utilization for App Services
   AppServiceAppLogs
   | where TimeGenerated > ago(7d)
   | summarize avg(CpuTime) by Resource, bin(TimeGenerated, 1h)
   
   // Cosmos DB RU consumption  
   AzureDiagnostics
   | where ResourceProvider == "MICROSOFT.DOCUMENTDB"
   | where TimeGenerated > ago(7d)
   | summarize avg(RequestCharge) by Resource
   
   // Storage account access patterns
   StorageBlobLogs
   | where TimeGenerated > ago(7d)
   | summarize RequestCount=count() by AccountName, bin(TimeGenerated, 1d)
  1. Calculate Baseline Metrics:
  1. VALIDATE CURRENT COSTS:

Step 4: Generate Cost Optimization Recommendations

Action: Analyze resources to identify optimization opportunities

Tools: Local analysis using collected data

Process:

  1. Apply Optimization Patterns based on resource types found:

Compute Optimizations:

Database Optimizations:

Storage Optimizations:

Infrastructure Optimizations:

  1. Calculate Evidence-Based Savings:
  1. Calculate Priority Score for each recommendation:
   Priority Score = (Value Score × Monthly Savings) / (Risk Score × Implementation Days)
   
   High Priority: Score > 20
   Medium Priority: Score 5-20
   Low Priority: Score < 5
  1. Validate Recommendations:

Step 5: User Confirmation

Action: Present summary and get approval before creating GitHub issues

Process:

  1. Display Optimization Summary:
   🎯 Azure Cost Optimization Summary
   
   📊 Analysis Results:
   • Total Resources Analyzed: X
   • Current Monthly Cost: $X 
   • Potential Monthly Savings: $Y 
   • Optimization Opportunities: Z
   • High Priority Items: N
   
   🏆 Recommendations:
   1. [Resource]: [Current SKU] → [Target SKU] = $X/month savings - [Risk Level] | [Implementation Effort]
   2. [Resource]: [Current Config] → [Target Config] = $Y/month savings - [Risk Level] | [Implementation Effort]
   3. [Resource]: [Current Config] → [Target Config] = $Z/month savings - [Risk Level] | [Implementation Effort]
   ... and so on
   
   💡 This will create:
   • Y individual GitHub issues (one per optimization)
   • 1 EPIC issue to coordinate implementation
   
   ❓ Proceed with creating GitHub issues? (y/n)
  1. Wait for User Confirmation: Only proceed if user confirms

Step 6: Create Individual Optimization Issues

Action: Create separate GitHub issues for each optimization opportunity. Label them with "cost-optimization" (green color), "azure" (blue color).

MCP Tools Required: create_issue for each recommendation

Process:

  1. Create Individual Issues using this template:

Title Format: [COST-OPT] [Resource Type] - [Brief Description] - $X/month savings

Body Template:

   ## 💰 Cost Optimization: [Brief Title]
   
   **Monthly Savings**: $X | **Risk Level**: [Low/Medium/High] | **Implementation Effort**: X days
   
   ### 📋 Description
   [Clear explanation of the optimization and why it's needed]
   
   ### 🔧 Implementation
   
   **IaC Files Detected**: [Yes/No - based on file_search results]
   

If IaC files found: Show IaC modifications + deployment

File: infrastructure/bicep/modules/app-service.bicep

Change: sku.name: 'S3' → 'B2'

az deployment group create --resource-group [rg] --template-file infrastructure/bicep/main.bicep

If no IaC files: Direct Azure CLI commands + warning

⚠️ No IaC files found. If they exist elsewhere, modify those instead.

az appservice plan update --name [plan] --sku B2

   
   ### 📊 Evidence
   - Current Configuration: [details]
   - Usage Pattern: [evidence from monitoring data]
   - Cost Impact: $X/month → $Y/month
   - Best Practice Alignment: [reference to Azure best practices if applicable]
   
   ### ✅ Validation Steps
   - [ ] Test in non-production environment
   - [ ] Verify no performance degradation
   - [ ] Confirm cost reduction in Azure Cost Management
   - [ ] Update monitoring and alerts if needed
   
   ### ⚠️ Risks & Considerations
   - [Risk 1 and mitigation]
   - [Risk 2 and mitigation]
   
   **Priority Score**: X | **Value**: X/10 | **Risk**: X/10

Step 7: Create EPIC Coordinating Issue

Action: Create master issue to track all optimization work. Label it with "cost-optimization" (green color), "azure" (blue color), and "epic" (purple color).

MCP Tools Required: create_issue for EPIC

Note about mermaid diagrams: Ensure you verify mermaid syntax is correct and create the diagrams taking accessibility guidelines into account (styling, colors, etc.).

Process:

  1. Create EPIC Issue:

Title: [EPIC] Azure Cost Optimization Initiative - $X/month potential savings

Body Template:

   # 🎯 Azure Cost Optimization EPIC
   
   **Total Potential Savings**: $X/month | **Implementation Timeline**: X weeks
   
   ## 📊 Executive Summary
   - **Resources Analyzed**: X
   - **Optimization Opportunities**: Y  
   - **Total Monthly Savings Potential**: $X
   - **High Priority Items**: N
   
   ## 🏗️ Current Architecture Overview
   

graph TB subgraph "Resource Group: [name]" [Generated architecture diagram showing current resources and costs] end

   
   ## 📋 Implementation Tracking
   
   ### 🚀 High Priority (Implement First)
   - [ ] #[issue-number]: [Title] - $X/month savings
   - [ ] #[issue-number]: [Title] - $X/month savings
   
   ### ⚡ Medium Priority 
   - [ ] #[issue-number]: [Title] - $X/month savings
   - [ ] #[issue-number]: [Title] - $X/month savings
   
   ### 🔄 Low Priority (Nice to Have)
   - [ ] #[issue-number]: [Title] - $X/month savings
   
   ## 📈 Progress Tracking
   - **Completed**: 0 of Y optimizations
   - **Savings Realized**: $0 of $X/month
   - **Implementation Status**: Not Started
   
   ## 🎯 Success Criteria
   - [ ] All high-priority optimizations implemented
   - [ ] >80% of estimated savings realized
   - [ ] No performance degradation observed
   - [ ] Cost monitoring dashboard updated
   
   ## 📝 Notes
   - Review and update this EPIC as issues are completed
   - Monitor actual vs. estimated savings
   - Consider scheduling regular cost optimization reviews

Error Handling