Terraform
We recommend using tfswitch
to manage your Terraform versions.
Install tfswitch
:
Install Terraform:
Add the location of the tfswitch
binary to your PATH
:
Verify that the correct version of Terraform is installed:
Persist the location of Terraform versions managed by tfswitch
:
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 shell aliases (highly recommended)
Add the following aliases to your shell configuration file (for example ~/.bashrc
or ~/.zshrc
1):
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'