Skip to main content

A tool for estimating Terraform infrastructure costs with uncertainty analysis

Project description

TerraCost VSCode Extension

A powerful VSCode extension that brings TerraCost's infrastructure cost estimation and optimization directly into your editor. Get real-time cost estimates, AI-powered optimization suggestions, and inline cost displays for your Terraform files.

Features

🏗️ Sidebar Panel

  • Resources & Costs Tab: View all infrastructure resources with their monthly costs
  • AI Suggestions Tab: Get LLM-powered cost optimization recommendations
  • Timeframe Selector: Choose from 1 month to 2 years for cost projections
  • Real-time Updates: Automatically refreshes when Terraform files change

👻 Ghost Text in .tf Files

  • Inline Cost Display: See monthly costs directly in your Terraform files
  • Non-intrusive: Gray text that doesn't interfere with your code
  • Real-time Updates: Costs update as you modify your infrastructure
  • Tooltips: Hover for detailed cost breakdowns

🚀 Seamless Integration

  • CLI Integration: Works with your existing TerraCost Python package
  • File Watching: Automatically detects changes in .tf files
  • Context Menus: Right-click on .tf files for quick cost calculations
  • Terminal Integration: Opens dedicated terminal for TerraCost commands

Installation

Prerequisites

  1. TerraCost Python Package: Must be installed in your environment

    cd /path/to/terracost
    pip install -e .
    
  2. Python: Ensure Python is available in your PATH

  3. VSCode: Version 1.74.0 or higher

Extension Installation

  1. Clone this repository
  2. Install dependencies:
    npm install
    
  3. Compile the extension:
    npm run compile
    
  4. Press F5 in VSCode to run the extension in development mode
  5. Or package and install:
    npm run vscode:prepublish
    # Install the generated .vsix file
    

Usage

Opening the Panel

  1. Click the TerraCost icon in the VSCode sidebar (🏗️)
  2. The panel opens with two tabs: "Resources & Costs" and "AI Suggestions"

Calculating Costs

  1. Select Timeframe: Choose from 1m, 3m, 6m, 1y, or 2y
  2. Click "Calculate Costs": Executes terracost plan in your workspace
  3. View Results: See total cost and per-resource breakdown
  4. Check Terminal: Detailed output appears in the integrated terminal

Getting AI Suggestions

  1. Click "Get AI Suggestions": Executes terracost suggest --savings
  2. View Options: See conservative, moderate, and aggressive optimization strategies
  3. Understand Changes: Each suggestion includes explanations and risk assessments

Ghost Text Features

  • Automatic Display: Cost estimates appear automatically in .tf files
  • Configuration: Toggle ghost text on/off in VSCode settings
  • Customization: Adjust colors and display options

Configuration

Extension Settings

{
  "terracost.timeframe": "1m",
  "terracost.showGhostText": true,
  "terracost.ghostTextColor": "#6a737d",
  "terracost.pythonPath": "python"
}

Environment Variables

Ensure these are set for full functionality:

export OPENAI_API_KEY="your-openai-api-key"  # For AI suggestions
export AWS_PROFILE="default"                  # For AWS pricing
export AWS_REGION="us-east-1"                # For AWS pricing

Development

Project Structure

terracost-vscode/
├── src/
│   ├── extension.ts              # Main extension logic
│   ├── webview/                  # Sidebar panel UI
│   │   ├── panel.ts             # Webview panel management
│   │   ├── main.js              # Frontend JavaScript
│   │   └── style.css            # Styling
│   └── providers/               # Core functionality
│       ├── costProvider.ts      # Cost calculation logic
│       └── ghostTextProvider.ts # Inline cost display
├── resources/
│   └── icon.svg                 # Extension icon
└── package.json                 # Extension manifest

Building

# Development build with watch
npm run watch

# Production build
npm run compile

# Linting
npm run lint

# Testing
npm test

Key Components

CostProvider

  • Executes TerraCost CLI commands
  • Parses output for cost information
  • Manages cost caching
  • Handles workspace changes

GhostTextProvider

  • Implements VSCode's InlayHintsProvider
  • Shows inline cost estimates
  • Updates in real-time
  • Configurable display options

TerraCostPanel

  • Manages the sidebar webview
  • Handles user interactions
  • Communicates with extension
  • Provides responsive UI

Troubleshooting

Common Issues

TerraCost Command Not Found

  • Ensure TerraCost is installed: pip install -e .
  • Check Python path in extension settings
  • Verify workspace has Terraform files

No Cost Estimates Displayed

  • Check if .tf files are in the workspace
  • Verify AWS credentials are configured
  • Look for errors in VSCode's Developer Console

Ghost Text Not Showing

  • Enable ghost text in extension settings
  • Ensure .tf files are open
  • Check if costs have been calculated

AI Suggestions Not Working

  • Verify OPENAI_API_KEY is set
  • Check internet connectivity
  • Ensure Terraform files contain AWS resources

Debug Mode

  1. Press Ctrl+Shift+P (or Cmd+Shift+P on Mac)
  2. Run "Developer: Toggle Developer Tools"
  3. Check Console for error messages
  4. Use VSCode's built-in debugging features

Contributing

Development Setup

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Code Style

  • Follow TypeScript best practices
  • Use VSCode's built-in formatting
  • Maintain consistent naming conventions
  • Add JSDoc comments for public APIs

Roadmap

Planned Features

  • Multi-cloud support (Azure, GCP)
  • Cost history tracking
  • Budget alerts and notifications
  • Integration with VSCode's Problems panel
  • Cost comparison between different configurations
  • Export cost reports to various formats

Known Limitations

  • Currently AWS-focused (following TerraCost CLI)
  • Requires TerraCost Python package to be installed
  • Ghost text updates may have slight delays
  • Some complex Terraform configurations may not parse perfectly

License

This extension is licensed under the MIT License, matching the TerraCost project.

Support

  • Issues: Report bugs and feature requests on GitHub
  • Documentation: Check the TerraCost main project for CLI details
  • Community: Join discussions in the TerraCost repository

Note: This extension requires the TerraCost Python package to be installed and accessible in your environment. Make sure to follow the main TerraCost project's installation instructions first.

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

terracost-0.1.0.tar.gz (33.0 kB view details)

Uploaded Source

Built Distribution

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

terracost-0.1.0-py3-none-any.whl (34.9 kB view details)

Uploaded Python 3

File details

Details for the file terracost-0.1.0.tar.gz.

File metadata

  • Download URL: terracost-0.1.0.tar.gz
  • Upload date:
  • Size: 33.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for terracost-0.1.0.tar.gz
Algorithm Hash digest
SHA256 37c7c7078e53ff21630940965079205ec2b98a0a4edd6af638921383d038c46f
MD5 d26d6b723b9778e639c04e7a8bd0961d
BLAKE2b-256 e3b8d7157813a913e0ec65f39a441c95171d6e2e8b63544348336ac4c5466bf0

See more details on using hashes here.

File details

Details for the file terracost-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: terracost-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 34.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for terracost-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac7d5c083557166aff1cec22124d304c6c16f7cf9bc222e38753d3afebbc617e
MD5 2f7f1b9f5d44e6ca58e238db41d0214f
BLAKE2b-256 f2dbe5f26af1f414cf09418bc2883792a9d7e9e4dd5415e32646828cc149a5a8

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