Terrafun is a tool for managing terraform versions. It enables seemless switching between different terraform versions which can be controlled by an environment variable, file, or user profile. It has been written in PowerShell but has been designed to support being used across multiple platforms and from different shells.
- terraform version management
Once you have PowerShell installed this module can be installed from the from the PowerShell Gallery.
OS | Edition | Build |
---|---|---|
Windows | Windows PowerShell (v5) |
|
Windows | PowerShell Core (v6+) |
|
Linux | PowerShell Core (v6+) |
|
MacOs | PowerShell Core (v6+) |
Install-Module terrafun -Force
pwsh -c "Install-Module terrafun -Force"
Uninstall-Module -Name terrafun -AllVersions -Force
Install-Module terrafun -Force
Install the module and simply run tf
in place of terraform
.
E.g:
tf version
tf init
tf plan
tf apply
You can use this from other shells (bash, zsh, sh, etc) through aliases providing you have a working PowerShell installation on your workstation. You can create aliases named to terraform
instead of tf
if you prefer.
- Install PowerShell on your machine
- Install the module using the instructions above
- Create an alias for your actual shell, examples below....
echo "alias tf='pwsh -c tf'" >> ~/.bashrc
alias tf='pwsh -c tf'
echo "alias tf='pwsh -c tf'" >> ~/.zshrc
alias tf='pwsh -c tf'
Other than a couple of commands for version management you use tf
exactly the same as if you are executing terraform
directly.
Command | Description |
---|---|
tf version list |
list available terraform versions |
tf version <version> |
set a specific version of terraform for the current directory |
tf version <version> global |
set a specific version of terraform across your user profile |
There are three methods for selecting the desired version of terraform, prioritized in the following order:
- Environment Variable
- File
- User Profile
Set the terraformversion
environment variable and you will get that version of terraform
terraformversion="1.0.0"
tf
$env:terraformversion = "1.0.0"
tf
Use the tf version {version}
command which will save the version into a file named .terraformversion
in the current directory.
tf version 0.13.5
Use the tf version {version} global
command which will store the version infomation in a config file within your user profile: ~/.terrafun/config.json
tf version 0.13.5 global
Binaries are downloaded to the following directory in your user profile:
~/.terrafun/terraform_{version}_{platform}_{arch}/terraform(.exe)