Thanks to visit codestin.com
Credit goes to github.com

Skip to content

anindya-dey/tfvm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Terraform Version Manager (TFVM)

A modern, fast CLI tool to manage multiple Terraform versions on your system

npm version Total Downloads license Node.js CI

Never worry about Terraform version conflicts again! πŸš€
Seamlessly switch between Terraform versions for different projects, just like nvm for Node.js.

🎯 Why TFVM?

  • 🏒 Multiple Projects? Different projects often require different Terraform versions
  • πŸ”„ Legacy Support? Need to maintain older infrastructure with specific Terraform versions
  • πŸ†• Latest Features? Want to try new Terraform features without breaking existing workflows
  • πŸ‘₯ Team Consistency? Ensure your entire team uses the same Terraform version
  • πŸ›‘οΈ Risk Mitigation? Test upgrades safely before applying to production

TFVM solves all of this with simple, intuitive commands.

✨ What's New in v2.0

  • ⚑ Faster & Lighter - Reduced bundle size to ~9KB (98% smaller!)
  • πŸ”„ Auto-Update Check - Get notified when new versions are available
  • 🌐 Modern APIs - Built with Fetch API for Node.js 18+ compatibility
  • πŸ§ͺ Better Testing - Comprehensive test suite with Bun test runner
  • πŸ“¦ Fewer Dependencies - Streamlined to essential packages only
  • πŸš€ Improved Performance - Optimized async operations throughout

πŸš€ Quick Start

Requirements: Node.js >= 18.0.0

Install globally via npm:

npm install -g tfvm

Or with other package managers:

# Using yarn
yarn global add tfvm

# Using pnpm  
pnpm add -g tfvm

# Using bun
bun add -g tfvm

default

🎬 Quick Demo

# 1. Install a specific Terraform version
$ tfvm download 1.6.0

# 2. Switch to it  
$ tfvm use

# 3. Verify it's active
$ terraform version
Terraform v1.6.0

# 4. List all your versions
$ tfvm list

✨ Features

  • πŸ”„ Easy version switching - Switch between Terraform versions with one command
  • πŸ“¦ Automatic downloads - Download any Terraform version from HashiCorp's official releases
  • 🎯 Interactive prompts - User-friendly selection menus and confirmations
  • πŸ—‚οΈ Local management - Keep multiple versions locally and switch as needed
  • πŸ–₯️ Cross-platform - Works on Windows, macOS, and Linux
  • ⚑ Fast & lightweight - Optimized bundle size (~9KB) with minimal dependencies
  • πŸ”§ Configurable - Customize storage directory via configuration files
  • πŸ›‘οΈ Safe operations - Confirmation prompts for destructive actions
  • πŸ” Version discovery - Browse all available Terraform releases
  • πŸ“Š Smart filtering - Automatically handles platform-specific downloads
  • πŸ”” Update notifications - Get notified when new TFVM versions are available

πŸš€ Common Use Cases

πŸ—οΈ Project-specific Terraform versions
# For legacy project requiring Terraform 1.4.x
cd legacy-infrastructure
tfvm use  # Select 1.4.6

# For new project using latest features  
cd new-infrastructure
tfvm use  # Select 1.6.0
πŸ”¬ Testing Terraform upgrades
# Download the new version
tfvm download 1.6.0

# Test with new version
tfvm use  # Select 1.6.0
terraform plan

# Rollback if issues found
tfvm use  # Select your stable version
πŸ‘₯ Team synchronization
# Team lead shares the version
echo "Team is using Terraform 1.5.7"

# Everyone downloads the same version
tfvm download 1.5.7
tfvm use  # Select 1.5.7

# Verify consistency
terraform version

πŸ“‹ Available Commands

tfvm list | tfvm ls

List locally downloaded Terraform versions or browse remote versions.

Local versions:

tfvm list    # Show all locally installed versions
tfvm ls      # Short alias

ls

Remote versions:

tfvm list --remote    # Browse all available versions from HashiCorp
tfvm ls -r           # Short alias with flag

ls-remote

No versions installed:

ls-when-empty


tfvm download | tfvm d

Download and install Terraform versions from HashiCorp's official releases.

Interactive download:

tfvm download    # Browse and select from all available versions
tfvm d          # Short alias

download

Version-specific download:

tfvm download 1.6.0    # Download specific version releases
tfvm d 1.6.0          # Short alias

download-version


tfvm remove | tfvm rm

Remove installed Terraform versions from your system.

Remove specific version:

tfvm remove    # Select which version to remove
tfvm rm       # Short alias

remove

Remove all versions:

tfvm remove --all    # Remove all installed versions
tfvm rm -a          # Short alias with flag

remove-all


tfvm use

Set a specific Terraform version as the default system version.

tfvm use    # Select from installed versions to set as default

use

πŸ’‘ Note: You may need to add the TFVM directory to your PATH environment variable. The tfvm dir command shows the exact path to add.


tfvm dir

Display the directory where Terraform executables are stored.

tfvm dir    # Shows storage directory (default: ~/.tfvm)

dir

πŸ”§ Configuration

TFVM can be configured using RC files. Create a .tfvmrc file in your home directory:

{
  "TERRAFORM_RELEASE_REPO": "https://releases.hashicorp.com/terraform",
  "STORAGE_DIR": "/custom/path/to/terraform/versions",
  "TFVM_PATH": "/custom/path/to/terraform/versions"
}

Environment Variables

You can also use environment variables for configuration:

export TFVM_STORAGE_DIR="/opt/terraform-versions"
export TFVM_PATH="/opt/terraform-versions"

Advanced Configuration

Custom Release Repository
{
  "TERRAFORM_RELEASE_REPO": "https://your-custom-mirror.com/terraform"
}
Corporate Environment Setup
# Set custom paths for corporate environments
export TFVM_STORAGE_DIR="/shared/tools/terraform"
export TFVM_PATH="/shared/tools/terraform"

# Or create a system-wide config
sudo mkdir -p /etc/tfvm
echo '{"STORAGE_DIR": "/shared/tools/terraform"}' | sudo tee /etc/tfvm/config.json

πŸ› οΈ Development

This project is built with modern tools for optimal performance:

  • Runtime - Node.js 18+ (for production) / Bun (for development)
  • TypeScript - Type-safe development with ESNext features
  • Bun - Fast bundling and testing
  • Modern APIs - Fetch API for HTTP requests (Node.js 18+)
  • Modern Dependencies:
    • citty - Modern lightweight CLI framework
    • @clack/prompts - Beautiful interactive prompts
    • node-html-parser - Fast HTML parsing
    • fflate - Fast ZIP compression
    • chalk v4 - Terminal string styling (CommonJS compatible)

Building from source

# Clone the repository
git clone https://github.com/anindya-dey/tfvm.git
cd tfvm

# Install dependencies with Bun (recommended)
bun install

# Or use npm/pnpm/yarn
npm install

# Build the project (creates Node.js-compatible bundle)
bun run build

# Run tests
bun test

# Run tests with coverage
bun run test:coverage

# Type check
bun run lint

# Link for local development
npm link

Tech Stack Details

Development:

  • Built with Bun for fast development experience
  • TypeScript with strict mode enabled
  • ES modules in source code
  • Comprehensive test suite using Bun's test runner
  • CI/CD with GitHub Actions testing Node.js 18, 20, and 22

Production:

  • Bundled to CommonJS for broad Node.js compatibility
  • Minified output (~11KB)
  • Node.js 18+ required (uses native Fetch API)
  • Zero TypeScript runtime dependencies
  • Modern, lightweight dependencies

πŸ“ Storage Structure

TFVM organizes Terraform versions in your home directory:

~/.tfvm/
β”œβ”€β”€ terraform_1.5.0      # Terraform v1.5.0 executable
β”œβ”€β”€ terraform_1.6.0      # Terraform v1.6.0 executable  
β”œβ”€β”€ terraform_1.7.0      # Terraform v1.7.0 executable
β”œβ”€β”€ terraform            # Symlink to currently active version
└── .version-check       # Update check cache (auto-managed)

πŸ” Troubleshooting

❓ Command not found after installation

Problem: tfvm: command not found

Solutions:

  1. Ensure ~/.tfvm is in your PATH environment variable
  2. Run tfvm dir to see the exact path to add
  3. Restart your terminal/shell
  4. For global npm installs, check npm config get prefix
# Add to your shell profile (.bashrc, .zshrc, etc.)
export PATH="$HOME/.tfvm:$PATH"
🌐 Network issues during download

Problem: Downloads fail or timeout

Solutions:

  1. Check internet connectivity
  2. Verify access to https://releases.hashicorp.com
  3. Check if you're behind a corporate firewall
  4. Try using a VPN or different network
# Test connectivity
curl -I https://releases.hashicorp.com/terraform/
πŸ” Permission errors

Problem: Permission denied errors

Solutions:

  1. Ensure write permissions to home directory
  2. On Unix systems, make executables executable
  3. Check file ownership
  4. Avoid using sudo with tfvm
# Fix permissions on Unix systems
chmod +x ~/.tfvm/terraform_*
chown -R $USER:$USER ~/.tfvm/
πŸ”„ Terraform version not switching

Problem: terraform version shows wrong version after tfvm use

Solutions:

  1. Check if PATH includes TFVM directory first
  2. Restart terminal session
  3. Verify no other Terraform installations override
  4. Check for shell aliases
# Debug PATH order
echo $PATH | tr ':' '\n' | grep -E "(tfvm|terraform)"

# Check which terraform binary is being used
which terraform
πŸ—‚οΈ Storage directory issues

Problem: Can't find downloaded versions

Solutions:

  1. Run tfvm dir to see current storage location
  2. Check if custom config is overriding default path
  3. Verify directory permissions
# Check storage directory
tfvm dir
ls -la $(tfvm dir)

🀝 Contributing

We welcome contributions! TFVM is open source and community-driven.

Quick Contribution Guide

  1. 🍴 Fork the repository
  2. 🌿 Create your feature branch (git checkout -b feature/amazing-feature)
  3. ✨ Make your changes with tests
  4. βœ… Test your changes (bun test)
  5. πŸ“ Commit your changes (git commit -m 'Add amazing feature')
  6. πŸš€ Push to the branch (git push origin feature/amazing-feature)
  7. πŸ“¬ Open a Pull Request

πŸ“š Documentation

For detailed guides on contributing and releasing:

Development Setup

# Clone and setup
git clone https://github.com/anindya-dey/tfvm.git
cd tfvm
bun install

# Make changes and test
bun run build
bun test

# Check types
bun run lint

# Link for local testing
npm link

# Test the CLI locally
tfvm --version

πŸ› Bug Reports

Found a bug? Please open an issue with:

  • Environment details (OS, Node.js version, etc.)
  • Steps to reproduce the issue
  • Expected vs actual behavior
  • Screenshots or terminal output if applicable

πŸ’‘ Feature Requests

Have an idea? We'd love to hear it! Open an issue describing:

  • The problem you're trying to solve
  • Your proposed solution
  • Alternative solutions you've considered
  • Use cases and examples

🎯 Areas We Need Help

  • πŸ§ͺ Testing - More test coverage and edge cases
  • πŸ“– Documentation - Improve guides and examples
  • 🌍 Internationalization - Support for other languages
  • πŸš€ Performance - Optimization and speed improvements
  • πŸ”§ Features - New functionality and enhancements

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

  • Inspiration: nvm for Node.js version management
  • Documentation: GIFs created using terminalizer
  • Built with: Bun for blazing-fast development
  • Creator: Built with ❀️ by Anindya Dey
  • Community: Thanks to all contributors and users!

πŸ“ˆ Project Stats

  • 🎯 Bundle Size: ~11KB (minified)
  • πŸ§ͺ Test Coverage: 28 passing tests
  • πŸ“¦ Dependencies: 5 runtime, 3 dev
  • πŸš€ Performance: Built with modern Fetch API
  • ⚑ Development: Powered by Bun
  • πŸ”„ CI/CD: Automated testing on Node.js 18, 20, 22

⭐ If TFVM helps you, please consider giving it a star on GitHub! ⭐

GitHub stars

Made with TypeScript & Bun β€’ Powered by Open Source β€’ Built for Developers

Report Bug Β· Request Feature Β· Contribute