tfswitch · the right Terraform version, automatically

3 months ago

Every Terraform project pins its own version. Run the wrong one, and Terraform stops with a version error before it does anything. tfswitch downloads and switches to the right version on demand.

Ask

Ask about this presentation

Answers are generated from this presentation.

Chapters

  1. 0:00tfswitch
  2. 0:11One command line tool
  3. 0:24Install it
  4. 0:31The first win: a version dropdown
  5. 0:43Or pin one on the command line
  6. 0:57The payoff: it reads your project
  7. 1:11The right version, automatically
Show transcript

tfswitch

tfswitch logo

Install and switch Terraform and OpenTofu versions on demand.

run tfswitch → pick a version → it is your active terraform

Every Terraform project pins its own version. Run the wrong one, and Terraform stops with a version error before it does anything. tfswitch downloads and switches to the right version on demand.

One command line tool

It downloads and switches between released versions, then makes your choice the active binary.

Terraform + OpenTofu → one tfswitch workflow

tfswitch is one small command line tool. It downloads and switches between versions on demand, then makes your choice the active terraform binary. The same workflow covers both Terraform and OpenTofu, so you never hand manage binaries again.

Install it

# macOS or Linux, with Homebrew
brew install warrensbox/tap/tfswitch
# or on any Linux box, run the install script
curl -L https://raw.githubusercontent.com/warrensbox/\
terraform-switcher/master/install.sh | bash

One binary, no dependencies.

Install it with Homebrew, on macOS or Linux. Or on any Linux box, pipe the install script. Either way, you get a single binary with no dependencies.

The first win: a version dropdown

Running tfswitch opens an interactive version dropdown

Arrow through every released version · press Enter to download and switch.

Now the first win. Just run tfswitch. It shows every released version in a dropdown. Arrow to the one you want, press Enter, and it downloads and switches to it. Your most recent picks float to the top.

Or pin one on the command line

tfswitch 1.7.0       # switch to exactly 1.7.0
tfswitch --latest    # newest stable release

tfswitch --list-all lists every version, including beta, alpha, and rc builds.

Already know the version you need? Pass it as an argument. tfswitch 1.7.0 grabs exactly that. Or ask for the latest stable release. Add the list all flag to see every version, including beta, alpha, and release candidate builds.

The payoff: it reads your project

terraform {
  required_version = ">= 0.12.9"
}
tfswitch auto-detecting the required version from a project file

Precedence: config files › module required_version › TF_VERSION › command-line argument.

Here is the real payoff. Drop a version file in your project, or add a required version to your Terraform. Then just run tfswitch with no arguments. It reads the constraint and installs the matching version. Change into any repository, and the correct version is active, every time.

The right version, automatically

  • Dropdown · pick any released version interactively.
  • Pin · pass an exact version on the command line.
  • Auto-detect · reads your project's required version.
  • Terraform + OpenTofu · the same workflow for both.

brew install warrensbox/tap/tfswitch  ·  tfswitch.warrensbox.com

That is the whole idea. Pick from a dropdown, pin one on the command line, or let tfswitch read your project and switch automatically. It handles Terraform and OpenTofu the same way. Install it, and start from the docs.