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
How to use
Check if tfenv is properly installed
Pick the terraform version you want and use the tfenv install command :
List remotes :
As alternative, for checking available terraform versions you can check the list in here :
https://releases.hashicorp.com/terraform /
Use the terraform version you’ve just installed
Check that proper terraform version is used
List all currently installed terraform versions :
For windows (git-bash):
Check out tfenv into any path (here is ${HOME}/.tfenv)
Add ~/.tfenv/bin to your $PATH any way you like
OR 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!
On 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.
Links :
https://github.com/tfutils/tfenv