TFSwitch: how to manage different terraform versions for each project

Terraform is a fantastic opensource tool that allows you to create, modify and enhance your infrastructure, allowing you to define your resources through declarative configuration files that can be edited, reviewed, versioned and shared amongst team members.
As infrastructure providers like AWS, Azure or GCP evolve and add new features and services every day, Terraform itself is continuously reviewed and enhanced by Hashicorp and the community to support new features and services.
This results in a very active development cycle, with new releases being very frequent, new features being introduced all the time, and ongoing changes that may require intervention and modifications to our templates. While it is possible to update your templates trying to chase and respect the changes introduced by HashiCorp, it is also true that this a time-consuming activity that can get very difficult when you have several projects. At the same time, you may need to use different Terraform versions for convenience or compatibility issues.

So, how can we switch between different versions of Terraform?

Tfswitch is a simple command line tool lets you download and switch between different versions of Terraform. If you have to work on a project that requires a particular version of Terraform and you don't have it installed, tfswitch will download that version.
Tfswitch is available for MacOS and Linux based operating systems, but it can also be used on Windows via WSL/WSL2. 

Installation on MacOS

The installation on MacOS requires Homebrew/Brew. Once this dependency is satisfied, this command will suffice:

brew install warrensbox/tap/tfswitch

Installation on Linux (or WSL/WSL2)
On Linux (or WSL/WSL2) there are various solutions.

We can download and use the installation bash script:

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

Use Snap if installed and available on our system:

sudo snap install tfswitch

If you use Arch or Arch-based distros and feel the need to show and demonstrate your superiority:

# compiled from source

yay tfswitch

# precompiled

yay tfswitch-bin

If you prefer the "old but gold" way you can always install from source.

Comments