DEV Community

Sahithi V
Sahithi V

Posted on

Manage Multiple Terraform Versions with tfswitch

That’s where terraform-switcher (tfswitch) comes to the rescue.


💡 What Is tfswitch?

tfswitch is a simple command-line tool that helps you install and switch between different Terraform versions instantly.

You can think of it like nvm (Node Version Manager) — but for Terraform.


🚀 Why You Need It

In real-world projects, different environments or teams may lock Terraform to different versions.

For example:

  • A legacy infrastructure might still use Terraform 0.14
  • A new project might use Terraform 1.7+
  • A CI/CD pipeline might expect a specific version declared in .terraform-version

Instead of manually downloading .zip files, updating paths, or reinstalling Terraform every time — tfswitch makes it seamless.


⚙️ Installation

On macOS (via Homebrew):

brew install warrensbox/tap/tfswitch
Enter fullscreen mode Exit fullscreen mode

On Linux:

curl -L https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh | bash
Enter fullscreen mode Exit fullscreen mode

On Windows (using Chocolatey):

choco install tfswitch
Enter fullscreen mode Exit fullscreen mode

🧠 How It Works

tfswitch detects the Terraform version you need in three ways:

1. From .terraform-version file

If your project includes a .terraform-version file:

1.5.7
Enter fullscreen mode Exit fullscreen mode

Just run:

tfswitch
Enter fullscreen mode Exit fullscreen mode

It will automatically install and switch to that version.


2. From required_version in Terraform configuration

terraform {
  required_version = ">= 1.4.0"
}
Enter fullscreen mode Exit fullscreen mode

tfswitch can read and match it automatically.


3. Manual Selection

tfswitch
Enter fullscreen mode Exit fullscreen mode

You’ll get an interactive menu to choose your desired version:

Use the arrow keys to navigate: ↓ ↑ → ← 
Select Terraform version: 
  1.7.0
> 1.5.7
  1.4.6
  0.14.11
Enter fullscreen mode Exit fullscreen mode

🧩 Real-World Example

Imagine you have two Terraform projects:

  • Project A (old) requires Terraform 0.14.11
  • Project B (new) requires Terraform 1.6.0

With tfswitch, switching between them is as simple as:

cd projectA
tfswitch 0.14.11

cd ../projectB
tfswitch 1.6.0
Enter fullscreen mode Exit fullscreen mode

No path changes. No reinstallations. Just productivity.


🔁 In

Top comments (0)