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.2.tar.gz (19.3 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.2-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: costguard-0.2.2.tar.gz
  • Upload date:
  • Size: 19.3 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.2.tar.gz
Algorithm Hash digest
SHA256 d5623b183668d7f2f963d998d8ccc6853aa3b3d86dd99bbc37b2e20c5645360c
MD5 9d5841abd517de111289cd51fb0b537c
BLAKE2b-256 a1212c0ad5dee2f5985a1a109aa495d9c1d0ea91efc2cecd61c9380707347fd0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: costguard-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 21.2 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 54e0f635270af0b40378b5d1d374f930fd0683353952ee199515561f4a3b84b5
MD5 0b1cb4e8a5e1d4219a2094625f38f25c
BLAKE2b-256 653e082d4e730741e3b059a68b164b848e98c0f87213cfc306ea62dac6262ec1

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