Seemingly every time I check, there is a new version of Terraform out there. If you have been at the Infrastructure-as-Code game for a bit using Terraform, most likely you understand the need to test and use different versions of Terraform.
Luckily there is a utility, tfenv (https://github.com/tfutils/tfenv), that makes switching a breeze.
Quick Install (Mac OS X)
$ brew install tfenvQuick Install (Linux)
$ git clone https://github.com/tfutils/tfenv.git ~/.tfenv
$ echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >> ~/.bash_profileNow install your desired version of Terraform! Here's what that looks like on my WSL / Debian environment.
$ tfenv install
Installing Terraform v0.12.24
Downloading release tarball from https://releases.hashicorp.com/terraform/0.12.24/terraform_0.12.24_linux_amd64.zip
############################################################################################################################################################# 100.0%Downloading SHA hash file from https://releases.hashicorp.com/terraform/0.12.24/terraform_0.12.24_SHA256SUMS
No keybase install found, skipping OpenPGP signature verification
Archive: tfenv_download.hzyDKi/terraform_0.12.24_linux_amd64.zip
inflating: /home/brian/.tfenv/versions/0.12.24/terraform
Installation of terraform v0.12.24 successful. To make this your default version, run 'tfenv use 0.12.24'
$ tfenv use 0.12.24
Switching default version to v0.12.24
Switching completed
$ terraform
Usage: terraform [-version] [-help] <command> [args]
The available commands for execution are listed below.
The most common, useful commands are shown first, followed by
less common or more advanced commands. If you're just getting
started with Terraform, stick with the common commands. For the
other commands, please read the help and docs before usage.
Common commands:
apply Builds or changes infrastructure
console Interactive console for Terraform interpolations
destroy Destroy Terraform-managed infrastructure
env Workspace management
fmt Rewrites config files to canonical format
get Download and install modules for the configuration
graph Create a visual graph of Terraform resources
import Import existing infrastructure into Terraform
init Initialize a Terraform working directory
output Read an output from a state file
plan Generate and show an execution plan
providers Prints a tree of the providers used in the configuration
push Upload this Terraform module to Atlas to run
refresh Update local state file against real resources
show Inspect Terraform state or plan
taint Manually mark a resource for recreation
untaint Manually unmark a resource as tainted
validate Validates the Terraform files
version Prints the Terraform version
workspace Workspace management
All other commands:
0.12checklist Checks whether the configuration is ready for Terraform v0.12
debug Debug output management (experimental)
force-unlock Manually unlock the terraform state
state Advanced state managementBAM! Easy!
Now that you've improved your workflow, get out there and break some stuff.