$npx -y skills add github/awesome-copilot --skill az-cost-optimizeAnalyze Azure resources used in the app (IaC files and/or resources in a target rg) and optimize costs - creating GitHub issues for identified optimizations.
| 1 | # Azure Cost Optimize |
| 2 | |
| 3 | 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. |
| 4 | |
| 5 | ## Prerequisites |
| 6 | - Azure MCP server configured and authenticated |
| 7 | - GitHub MCP server configured and authenticated |
| 8 | - Target GitHub repository identified |
| 9 | - Azure resources deployed (IaC files optional but helpful) |
| 10 | - Prefer Azure MCP tools (`azmcp-*`) over direct Azure CLI when available |
| 11 | |
| 12 | ## Workflow Steps |
| 13 | |
| 14 | ### Step 1: Get Azure Best Practices |
| 15 | **Action**: Retrieve cost optimization best practices before analysis |
| 16 | **Tools**: Azure MCP best practices tool |
| 17 | **Process**: |
| 18 | 1. **Load Best Practices**: |
| 19 | - Execute `azmcp-bestpractices-get` to get some of the latest Azure optimization guidelines. This may not cover all scenarios but provides a foundation. |
| 20 | - Use these practices to inform subsequent analysis and recommendations as much as possible |
| 21 | - Reference best practices in optimization recommendations, either from the MCP tool output or general Azure documentation |
| 22 | |
| 23 | ### Step 2: Discover Azure Infrastructure |
| 24 | **Action**: Dynamically discover and analyze Azure resources and configurations |
| 25 | **Tools**: Azure MCP tools + Azure CLI fallback + Local file system access |
| 26 | **Process**: |
| 27 | 1. **Resource Discovery**: |
| 28 | - Execute `azmcp-subscription-list` to find available subscriptions |
| 29 | - Execute `azmcp-group-list --subscription <subscription-id>` to find resource groups |
| 30 | - Get a list of all resources in the relevant group(s): |
| 31 | - Use `az resource list --subscription <id> --resource-group <name>` |
| 32 | - For each resource type, use MCP tools first if possible, then CLI fallback: |
| 33 | - `azmcp-cosmos-account-list --subscription <id>` - Cosmos DB accounts |
| 34 | - `azmcp-storage-account-list --subscription <id>` - Storage accounts |
| 35 | - `azmcp-monitor-workspace-list --subscription <id>` - Log Analytics workspaces |
| 36 | - `azmcp-keyvault-key-list` - Key Vaults |
| 37 | - `az webapp list` - Web Apps (fallback - no MCP tool available) |
| 38 | - `az appservice plan list` - App Service Plans (fallback) |
| 39 | - `az functionapp list` - Function Apps (fallback) |
| 40 | - `az sql server list` - SQL Servers (fallback) |
| 41 | - `az redis list` - Redis Cache (fallback) |
| 42 | - ... and so on for other resource types |
| 43 | |
| 44 | 2. **IaC Detection**: |
| 45 | - Use `file_search` to scan for IaC files: "**/*.bicep", "**/*.tf", "**/main.json", "**/*template*.json" |
| 46 | - Parse resource definitions to understand intended configurations |
| 47 | - Compare against discovered resources to identify discrepancies |
| 48 | - Note presence of IaC files for implementation recommendations later on |
| 49 | - Do NOT use any other file from the repository, only IaC files. Using other files is NOT allowed as it is not a source of truth. |
| 50 | - If you do not find IaC files, then STOP and report no IaC files found to the user. |
| 51 | |
| 52 | 3. **Configuration Analysis**: |
| 53 | - Extract current SKUs, tiers, and settings for each resource |
| 54 | - Identify resource relationships and dependencies |
| 55 | - Map resource utilization patterns where available |
| 56 | |
| 57 | ### Step 3: Collect Usage Metrics & Validate Current Costs |
| 58 | **Action**: Gather utilization data AND verify actual resource costs |
| 59 | **Tools**: Azure MCP monitoring tools + Azure CLI |
| 60 | **Process**: |
| 61 | 1. **Find Monitoring Sources**: |
| 62 | - Use `azmcp-monitor-workspace-list --subscription <id>` to find Log Analytics workspaces |
| 63 | - Use `azmcp-monitor-table-list --subscription <id> --workspace <name> --table-type "CustomLog"` to discover available data |
| 64 | |
| 65 | 2. **Execute Usage Queries**: |
| 66 | - Use `azmcp-monitor-log-query` with these predefined queries: |
| 67 | - Query: "recent" for recent activity patterns |
| 68 | - Query: "errors" for error-level logs indicating issues |
| 69 | - For custom analysis, use KQL queries: |
| 70 | ```kql |
| 71 | // CPU utilization for App Services |
| 72 | AppServiceAppLogs |
| 73 | | where TimeGenerated > ago(7d) |
| 74 | | summarize avg(CpuTime) by Resource, bin(TimeGenerated, 1h) |
| 75 | |
| 76 | // Cosmos DB RU consumption |
| 77 | AzureDiagnostics |
| 78 | | where ResourceProvider == "MICROSOFT.DOCUMENTDB" |
| 79 | | where TimeGenerated > ago(7d) |
| 80 | | summarize avg(RequestCharge) by Resource |
| 81 | |
| 82 | // Storage account access patterns |
| 83 | StorageBlobLogs |
| 84 | | where TimeGenerated > ago(7d) |
| 85 | | summarize RequestCount=count() by AccountName, bin(TimeGenerated, 1d) |
| 86 | ``` |
| 87 | |
| 88 | 3. **Calculate Baseline Metrics**: |
| 89 | - CPU/Memory utilization averages |
| 90 | - Database throughput patterns |
| 91 | - Storage access frequency |
| 92 | - Function execution rates |
| 93 | |
| 94 | 4. **VALIDATE CURRENT COSTS**: |
| 95 | - Using the SKU/tier configurations discovered in Step 2 |
| 96 | - Look up current Azure pricing at https://azure.microsoft.com/pricing/ or u |