Skip to main content

CostGuard CLI - Cloud Cost Analysis Tool

Project description

CostGuard CLI

Cloud cost analysis tool for Terraform. Get cost estimates before deploying infrastructure.

Installation

pip install git+https://github.com/buddypracticerepo1-stack/costguard-cli.git

Quick Start

# Configure API key
costguard configure --api-key YOUR_API_KEY

# Analyze a single project
costguard breakdown --path ./terraform

# Analyze multiple projects with config file
costguard breakdown --config costguard.yml

# Output as JSON
costguard breakdown --path ./terraform --format json

# Output for GitHub PR comment
costguard breakdown --config costguard.yml --format github-comment --out comment.md

Configuration

Create a costguard.yml in your repository root:

version: 1

projects:
  - path: infrastructure/aws
    name: AWS Production

  - path: infrastructure/gcp
    name: GCP Production

  - path: infrastructure/azure
    name: Azure Production

thresholds:
  warn_monthly_cost: 1000
  fail_monthly_cost: 10000

output:
  format: table
  show_resources: true

Project Options

Field Required Description
path Yes Path to Terraform directory
name No Display name (defaults to path)
terraform_var_files No List of .tfvars files to use
terraform_vars No Inline Terraform variables (key-value)
terraform_workspace No Terraform workspace name
usage_file No Path to usage file for usage-based pricing
skip No Skip this project (default: false)

Example with all options:

projects:
  - path: infrastructure/aws
    name: AWS Production
    terraform_var_files:
      - prod.tfvars
    terraform_vars:
      environment: production
      instance_count: "3"
    terraform_workspace: production
    usage_file: usage/aws-usage.yml
    skip: false

Commands

costguard breakdown

Analyze Terraform plans and show cost breakdown.

# Options
--path, -p       Path to Terraform directory
--config, -c     Path to costguard.yml
--format, -f     Output format: table, json, github-comment
--out, -o        Output file path
--resources      Show resource breakdown (default: true)
--api-key        CostGuard API key

costguard configure

Configure CLI settings.

costguard configure --api-key YOUR_KEY
costguard configure --show

costguard version

Show version information.

Environment Variables

Variable Description
COSTGUARD_API_KEY API key for authentication
COSTGUARD_API_URL API endpoint URL

CI/CD Integration

GitHub Actions

- name: Install CostGuard
  run: pip install git+https://github.com/buddypracticerepo1-stack/costguard-cli.git

- name: Analyze costs
  env:
    COSTGUARD_API_KEY: ${{ secrets.COSTGUARD_API_KEY }}
  run: |
    costguard breakdown --config costguard.yml --format github-comment --out comment.md

- name: Post PR comment
  uses: actions/github-script@v7
  with:
    script: |
      const fs = require('fs');
      const comment = fs.readFileSync('comment.md', 'utf8');
      github.rest.issues.createComment({
        owner: context.repo.owner,
        repo: context.repo.repo,
        issue_number: context.issue.number,
        body: comment
      });

GitLab CI

cost-check:
  image: python:3.11
  script:
    - pip install git+https://github.com/buddypracticerepo1-stack/costguard-cli.git
    - costguard breakdown --config costguard.yml --format json

Output Formats

Table (default)

  === CostGuard Cost Analysis ===

  Total Monthly Cost: $2,861.84
  Decision: [OK] ALLOW

  === Projects ===

  [OK] AWS Production
     Path: infrastructure/aws
     Cost: $2,725.00/month

JSON

{
  "status": "success",
  "decision": "ALLOW",
  "summary": {
    "total_monthly_cost": 2861.84
  },
  "projects": [...]
}

GitHub Comment

Markdown formatted for PR comments with collapsible resource sections.

License

MIT License - see LICENSE file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

costguard-0.2.0.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

costguard-0.2.0-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

Details for the file costguard-0.2.0.tar.gz.

File metadata

  • Download URL: costguard-0.2.0.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for costguard-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0ba92c17ddf623476f7b1a44a86497b369e6d12a7405622d2203a87f5207b634
MD5 51106fe0114091dc9a3b49f350ab1e82
BLAKE2b-256 41fc6fe2e0a7f2bc3d061dee4d4fa0a7bfe0374a6aa485577639db5a02ec3364

See more details on using hashes here.

File details

Details for the file costguard-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: costguard-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 20.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for costguard-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed00bfe803a6b167f2398d021b8f2536104caa8e553a38d10c9b6b43342ca427
MD5 84eeef1db19ede00290e58a7fc83fdf1
BLAKE2b-256 2109d31ba03bc3e4263e7211072341974eae12006c00e19560be2b8cc484ef6d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page