An AI-powered GitHub Action that automatically calculates and provides cost estimates for infrastructure changes in your Pull Requests.
- Add the action to your workflow:
name: IaC Cost Estimation
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
estimate-cost:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: linfieldlabs/iac-cost-estimator@v1
with:
iac-stack: "terraform" # Required: terraform or pulumi
iac-dir: "infrastructure" # Optional: defaults to root directory
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- Configure required secrets in your repository settings:
Name | Description |
---|---|
OPENAI_API_KEY |
Your OpenAI API key (or any compatible API) |
AWS_ACCESS_KEY_ID |
AWS access key for IaC operations |
AWS_SECRET_ACCESS_KEY |
AWS secret key for IaC operations |
GITHUB_TOKEN |
GitHub token for PR comments |
Name | Required | Default | Description |
---|---|---|---|
iac-stack |
Yes | terraform |
IaC platform (terraform or pulumi ) |
iac-dir |
No | "" |
Directory containing IaC files |
model |
No | gpt-4 |
LLM model to use |
model_base_url |
No | "" |
Custom model API endpoint |
- 🔄 Automatic cost analysis on PR changes
- 💰 Detailed cost breakdowns
- 📊 Usage-based scenarios (Low, Medium, High)
- 🏗️ Supports Terraform and Pulumi
- 🤖 AI-powered estimation
- 📝 Comprehensive PR comments
- ✅ Terraform
- ✅ Pulumi
This sample evaluates the cost estimation of a video processing pipeline deployed on AWS using Terraform. The architecture includes fixed-cost components (EC2, RDS, EIP) and variable-cost components (S3, Lambda, CloudWatch).
- Node.js v20 or later
- npm
- Terraform CLI (for Terraform support)
- Pulumi CLI (for Pulumi support)
- Clone the repository:
git clone https://github.com/yourusername/iac-cost-estimator.git
cd iac-cost-estimator
- Install dependencies:
npm install
- Configure environment variables:
Create a .env file in the src
directory. (Copy from .env.sample)
OPENAI_API_KEY=your_openai_api_key
AWS_ACCESS_KEY_ID=your_aws_access_key
AWS_SECRET_ACCESS_KEY=your_aws_secret_key
- Build the project:
npm run build
- Run tests:
npm test
├── src/
│ ├── estimators/ # IaC-specific cost estimators
│ ├── services/ # LLM service implementations
│ └── test/ # Test files and fixtures
├── .github/
│ └── workflows/ # GitHub Action workflows
└── dist/ # Compiled JavaScript
- Estimators: Handle IaC-specific operations (plan/preview generation)
- LLM Services: Interface with AI models for cost analysis
- Core Logic: Processes and formats cost estimations