Switching between different/multiple terraform versions
2022, Jun 06
Prerequisites
This can be achieved with an OS tool called tfenv
Currently tfenv supports the following OSes
- Mac OS X (64bit)
- Linux ( 64bit and Arm )
- Windows (64bit) - only tested in git-bash - currently presumed failing due to symlink issues in git-bash
Install tfenv via Homebrew for MacOS
brew install tfenvHow to use
Check if tfenv is properly installed
tfenv versionPick the terraform version you want and use the tfenv install command :
List remotes :
tfenv list-remoteAs alternative, for checking available terraform versions you can check the list in here :
https://releases.hashicorp.com/terraform /
tfenv install 0.15.1Use the terraform version you’ve just installed
tfenv use 0.15.1Check that proper terraform version is used
terraform --versionList all currently installed terraform versions :
tfenv listFor windows (git-bash):
Check out tfenv into any path (here is ${HOME}/.tfenv)
git clone https://github.com/tfutils/tfenv.git ~/.tfenvAdd ~/.tfenv/bin to your $PATH any way you like
$ echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >> ~/.bash_profileOR you can make symlinks for tfenv/bin/* scripts into a path that is already added to your $PATH (e.g. /usr/local/bin) OSX/Linux Only!
ln -s ~/.tfenv/bin/* /usr/local/binOn Ubuntu/Debian
Touching /usr/local/bin might require sudo access, but you can create ${HOME}/bin or ${HOME}/.local/bin and on next login it will get added to the session $PATH or by running . ${HOME}/.profile it will get added to the current shell session’s $PATH.
mkdir -p ~/.local/bin/
. ~/.profile
ln -s ~/.tfenv/bin/* ~/.local/bin
which tfenvLinks :
https://github.com/tfutils/tfenv