Switch Terraform Version

With several projects it happens that you need to switch the terraform version. The solution to this is a helper called tfswitch

How to manage different terraform versions for each project | by Warren Veerasingam | Medium

https://tfswitch.warrensbox.com/

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

Afterwards we can change the terraform version with

tfswitch          # give menu
tfswitch -l       # list all versions
tfswitch 0.12.9   # use version 0.12.9

In addition tfswitch reads the terraform file in the current directory

Running tfswitch without root permissions

The solution is quick and dirty, but it works. Create a private bin folder and add it to the path in .bashrc

wget https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh  #Get the installer

chmod 755 install.sh #Make installer executable

./install.sh -b $HOME/bin #Install tfswitch in local dir

export PATH=$PATH:$HOME/bin # Add to .bash_profile

#rename binary 

mv $HOME/bin/tfswitch $HOME/bin/tfswitch.bin

#create a batch file, paste all 4 lines together
cat > $HOME/bin/tfswitch <<EOL
#!/bin/bash
tfswitch.bin -b $HOME/bin/terraform
EOL

chmod 755 $HOME/bin/tfswitch

#test
tfswitch