Skip to content

Terraform

We recommend using tfswitch to manage your Terraform versions.

Install tfswitch:

brew install warrensbox/tap/tfswitch

Install Terraform:

tfswitch --latest

Add the location of the tfswitch binary to your PATH:

export PATH=$PATH:$HOME/bin

Verify that the correct version of Terraform is installed:

terraform version

Persist the location of Terraform versions managed by tfswitch:

echo 'export PATH=$PATH:$HOME/bin' >> ~/.zshrc
echo 'export PATH=$PATH:$HOME/bin' >> ~/.bash_profile

Executable PATH

Once you open a new terminal window the path to the Terraform binary managed by tfswitch will not be set.

To persist the path you must add the same command we ran manually in step 3 to your ~/.bash_profile or ~/.zshrc file. Below is an example of how to do this.

Caching Terraform plugins

Terraform can cache plugins. This saves you time when downloading the same plugin multiple times. More information can be found in HashiCorp's configuration reference

Alternatively you can refer to HashiCorp's guide for installing Terraform

Add the following aliases to your shell configuration file (for example ~/.bashrc or ~/.zshrc1):

alias tf='terraform'
alias tfa='tfswitch && terraform apply'
alias tfc='tfswitch && terraform console'
alias tfd='tfswitch && terraform destroy'
alias tff='tfswitch && terraform fmt'
alias tfi='tfswitch && terraform init'
alias tfo='tfswitch && terraform output'
alias tfp='tfswitch && terraform plan'
alias tfv='tfswitch && terraform validate'
alias tfl='tfswitch && terraform providers lock -platform=darwin_amd64 -platform=darwin_arm64 -platform=linux_amd64 -platform=windows_amd64'