TFENV vs TFSWITCH

Managing multiple versions of terraform

What are version managers?

  • Tools that allow you to install and switch between multiple versions of a programming language or other software.
  • Commonly used by developers to manage different versions of programming languages such as Ruby, Python, Node.js, and Go.
  • Can also be used to manage different versions of other software such as Terraform.

What are tfenv and tfswitch?

  • Popular version managers for terraform.
  • Simplify the process of installing and switching between multiple versions of Terraform.
  • Community driven projects.
  • TFEnv is written in Bash.
  • TFSwitch is written in Go.

Features of TFEnv

  • Version management.
  • Automatic version switching.
  • Easy installation.
  • Inspired by rbenv.
  • Written in Bash.

Pros and Cons of TFEnv

Pros:

  • Easy installation and management of multiple Terraform versions
  • Automatic version switching based on project configuration
  • Works on macOS, Linux, and Windows (through Windows Subsystem for Linux)

Cons:

  • No interactive CLI for selecting and switching Terraform versions
  • Relies on the presence of a “.terraform-version” file for automatic version switching, which may not be ideal for some workflows

How to install TFEnv

Through Homebrew on macOS/Linux

brew install tfenv

Manual

  • Check out tfenv into any path (here is ${HOME}/.tfenv)
git clone --depth=1 https://github.com/tfutils/tfenv.git ~/.tfenv
  • Add ~/.tfenv/bin to your $PATH any way you like
echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >> ~/.bash_profile

Using TFEnv

  • List all available versions
tfenv list-remote
  • Install a specific version
tfenv install 0.12.31
  • Switch to a specific version
tfenv use 0.12.31
  • Uninstall a specific version
tfenv uninstall 0.12.31
  • Install the latest version
tfenv install latest
  • Use the latest version
tfenv use latest

Features of TFswitch

  • Version management.
  • Easy-to-use interactive CLI
  • Easy installation.
  • Written in Go.

Pros and Cons of TFSwitch

Pros:

  • Simple installation and management of multiple Terraform versions
  • User-friendly interactive CLI for selecting and switching between versions
  • Works on macOS, Linux, and Windows (via WSL)
  • Can use an optional configuration file (e.g., “.tfswitchrc”) for setting default versions

Cons:

  • No automatic version switching based on project configuration (e.g., “.terraform-version” file)
  • Does not support uninstalling Terraform versions directly
  • No support for version aliases

How to install TFSwitch

Through Homebrew on macOS/Linux

brew install warrensbox/tap/tfswitch

Script

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

Manual

Download the binary from the releases page and put it in /usr/local/bin or any other location on your PATH.

Using TFEnv

  • Run the interactive CLI:
tfswitch
  • Select a version:
tfswitch 0.12.31
  • List all installed versions:
tfswitch -l
  • List all available versions:
tfswitch -l --all
  • Set a default version:
tfswitch -b 0.12.31
  • Set a default version for a specific directory:
tfswitch -b 0.12.31 /path/to/directory
  • Set a default version using a configuration file:
tfswitch -b 0.12.31 --rcfile .tfswitchrc
# or
echo "0.12.31" > .tfswitchrc
tfswitch --rc

Comparison of TFEnv and TFSwitch

  • Version management.
  • Automatic version switching.
  • Interactive CLI.
  • Platform support.
  • Community and support.
  • Installation.

Use cases

  • Small projects
  • Large projects
  • Team collaboration

Conclusion

  • Both tfenv and tfswitch are popular Terraform version managers that simplify the process of installing and switching between multiple versions of Terraform.
  • They offer unique features that cater to various use cases and user preferences.
  • Depending on your specific needs, one tool may be better suited for your Terraform projects than the other, you should consider yours and your team’s needs when choosing one over the other.

Thank you!