An enterprise-grade solution for optimizing Azure costs through automated analysis, real-time alerting, and intelligent recommendations. Now with full Windows support and Phase 1 enterprise features!
- Multi-Subscription Support: Manage costs across multiple Azure subscriptions
- Real-Time Alerting: Instant notifications via Slack, Teams, or email
- Intelligent Anomaly Detection: Advanced algorithms to identify cost spikes
- Resource Tagging Compliance: Automated enforcement of tagging policies
- Comprehensive Reporting: Detailed cost analysis and optimization recommendations
- Azure Policy Integration: Enforce governance and compliance across subscriptions
- Automated Resource Actions: Shut down idle VMs and clean up orphaned resources
- Budget Management: Automated budget creation and threshold monitoring
- Notification System: Multi-channel alerts for cost anomalies and optimization opportunities
- Azure Key Vault Integration: Secure credential and secret management
- Managed Identity Support: Secure authentication without stored credentials
- Private Endpoints: Secure network connectivity for enterprise environments
- RBAC Integration: Fine-grained access control and permission management
- Native Windows Support: PowerShell and batch deployment scripts
- Cross-Platform Compatibility: Works on Windows, Linux, and macOS
- Easy Installation: Multiple deployment options for different user preferences
# Clone and deploy in one command
git clone https://github.com/your-repo/azure-cost-optimizer.git
cd azure-cost-optimizer
.\scripts\deploy_phase1.ps1 -SubscriptionId "your-sub-id" -ResourceGroup "rg-cost-optimizer"# For basic deployments
scripts\deploy_phase1.bat "your-subscription-id" "rg-cost-optimizer"For detailed Windows setup instructions, see Windows Quick Start Guide
-
Resource Optimization
- Identifies idle VMs based on CPU usage metrics
- Recommends VM SKU downsizing for cost-efficient operations
- Detects orphaned (unattached) managed disks
- Identifies cost anomalies by comparing against baseline spending
-
Infrastructure as Code
- Terraform configuration for Azure resources
- Creates cost export schedules to Azure Storage
- Configures Log Analytics for resource metrics collection
- Sets up budget alerts for cost control
-
Security
- Azure Key Vault integration for secure credential storage
- Support for managed identities
- Secure storage of configuration with proper access controls
- Python 3.8+
- Terraform 1.5+
- Azure subscription with appropriate permissions
See requirements.txt for the complete list of dependencies. Key components:
- Azure SDK libraries
- Analytics and data processing libraries
- Testing and development utilities
azure-cost-optimizer/
β
βββ docs/ # Documentation
β βββ architecture.md # Solution architecture
β βββ usage.md # Detailed usage guide
β
βββ infra/ # Infrastructure as Code
β βββ main.tf # Main Terraform configuration
β βββ variables.tf # Terraform variables
β
βββ src/ # Source code
β βββ __init__.py # Package initialization
β βββ azure_client.py # Azure API client implementation
β βββ config.py # Configuration management
β βββ optimizer.py # Core optimization logic
β
βββ tests/ # Test suite
β βββ __init__.py # Test package initialization
β βββ test_azure_client.py # Tests for Azure client
β βββ test_optimizer.py # Tests for optimizer logic
β
βββ azure-pipelines.yml # CI/CD pipeline configuration
βββ LICENSE # Project license
βββ README.md # This file
βββ requirements.txt # Python dependencies
-
Clone the repository:
git clone https://github.com/arnabdey73/azure-cost-optimizer.git cd azure-cost-optimizer -
Set up a Python virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Authentication:
- Set up environment variables for Azure authentication:
# Service Principal authentication export AZURE_TENANT_ID="your-tenant-id" export AZURE_CLIENT_ID="your-client-id" export AZURE_CLIENT_SECRET="your-client-secret" export AZURE_SUBSCRIPTION_ID="your-subscription-id" # Optional: Log Analytics export LOG_ANALYTICS_WORKSPACE_ID="your-workspace-id"
- Or use Azure Key Vault for secure credential storage:
export AZURE_KEY_VAULT_URL="https://your-keyvault.vault.azure.net/"
- Set up environment variables for Azure authentication:
-
Initialize Terraform:
cd infra terraform init -
Configure Terraform variables: Create a
terraform.tfvarsfile with:subscription_id = "your-subscription-id" storage_account_name = "costoptimizer12345" # Must be globally unique allowed_ip_ranges = ["123.123.123.123"] # Your IP address
-
Deploy infrastructure:
terraform plan -out=tfplan terraform apply tfplan
Execute the optimizer to generate cost optimization recommendations:
python src/optimizer.py --subscription-id "your-subscription-id" --start-date "2025-05-01" --end-date "2025-05-28"See docs/usage.md for detailed command options and scenarios.
The optimizer generates a JSON file containing recommendations for:
- Idle VMs that could be shut down
- VMs that could be resized to smaller SKUs
- Orphaned disks that can be removed
- Cost anomalies that should be investigated
Example output:
{
"timestamp": "2025-05-28T14:30:00.000Z",
"idleVMs": [
{"resourceId": "/subscriptions/.../vm1", "averageCpu": 2.5}
],
"skuResizes": [
{"resourceId": "/subscriptions/.../vm2", "currentSku": "Standard_D8s_v3", "suggestedSku": "Standard_D4s_v3"}
],
"orphanedDisks": [
{"diskName": "disk1", "ageDays": 45}
],
"costAnomalies": [
{"date": "2025-05-15", "cost": 150.0, "baseline": 100.0}
]
}For more detailed information, please refer to the following documents:
- Architecture Overview - Solution architecture and component descriptions
- Detailed Usage Guide - Comprehensive instructions and examples
- API Reference - Detailed reference for all classes and methods
- Security Best Practices - Security guidelines for deployment
- Contributing Guidelines - How to contribute to this project
This application supports multiple authentication methods for Azure:
- Service Principal with Client Secret (stored securely in Key Vault)
- Managed Identity (recommended for production)
- DefaultAzureCredential (integrates with VS Code, Azure CLI, etc.)
For production use, we recommend:
- Use Key Vault for all secrets
- Enable diagnostic settings on all resources
- Implement resource locks to prevent accidental deletion
- Apply least-privilege permissions for service principals
Contributions are welcome! Please follow the guidelines in CONTRIBUTING.md (if available).
This project is licensed under the MIT License.