Lightweight bash script to manage and quickly switch terraform versions
Currently tested on macOS x64 and arm64. May test on Linux when I get to it, contributions welcome. This is a bash script, no native Windows support is planned - If you get this to work on WSL2, let me know ;)
- Download https://raw.githubusercontent.com/joerx/tfm/master/tfm and copy somewhere into your
$PATH
- Make sure
~/.local/bin
exists and is on your$PATH
- Alternatively, set
TFM_PREFIX
to a different value in your shell profile
# ~/.bash_profile
export PATH=$HOME/.local/bin:$PATH
# or:
export PATH=$HOME/.bin:$PATH
export TFM_PREFIX=$HOME/.bin
Usage:
$ tfm
Usage: tfm <subcommand> [args]
...
List versions:
Versions:
* 1.0.11
1.1.7
Aliases:
terraform = 1.0.11
tf10 = 1.0.11
tf11 = 1.1.7
Switch default version:
$ tfm use 1.1.7
Aliased terraform version 1.1.7 to terraform
Current terraform version is 1.1.7
$ terraform version
Terraform v1.1.7
Set an alias:
$ tfm alias 1.1.7 tf11
Aliased terraform version 1.1.7 to tf11
Install:
$ tfm install 1.1.7
...
List installation candidates:
$ tfm releases | grep ^1.1
By default, terraform versions are installed in ~/.tfm
and the terraform
binary will be linked to ~/.local/bin
.
Some env vars can be used to customize those defaults. Run tfm printenv
to see which ones exist and what the current values are:
$ tfm printenv
Architecture:
darwin_arm64
Environment:
TFM_PREFIX: /Users/joerg.henning/.local/bin
TFM_DIR: /Users/joerg.henning/.tfm
Thanks to Hashicorp for Terraform and nvm for inspiration.