DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

eelayoubi
eelayoubi

Posted on

Switching between multiple Terraform versions

Hey All,

In case you are using Terraform to provision and manage your infrastructure, you normally install a specific version on your machine (or on your CI servers).

But what if you wanted to install another terraform version to test it out?

In case you have multiple environment in the same codebase, let's say dev and prod, and you deployed both of them using a fixed terraform version (1.2.7).

After a while a new terraform version is available (1.3.1). You can update the version on your machine and test if it works fine, if not re-install the older version ... Which can be a bit cumbersome ...

Or, you can use tfenv which is a Terraform version manager.

After installing tfenv, you can use the tfenv list command to list the available terraform versions you have installed:

~ tfenv list
  1.2.7
No default set. Set with 'tfenv use <version>'
Enter fullscreen mode Exit fullscreen mode

There is a new terraform version available that I would like to test out.

To install it, you just simply run :

tfenv install 1.3.1
Installing Terraform v1.3.1
Downloading release tarball from https://releases.hashicorp.com/terraform/1.3.1/terraform_1.3.1_darwin_amd64.zip
######################################################################### 100.0%
Downloading SHA hash file from https://releases.hashicorp.com/terraform/1.3.1/terraform_1.3.1_SHA256SUMS
Not instructed to use Local PGP (/usr/local/Cellar/tfenv/3.0.0/use-{gpgv,gnupg}) & No keybase install found, skipping OpenPGP signature verification
Archive:  /var/folders/jl/tfyd0yns2xxgb_58fj3ljslc0000gn/T/tfenv_download.XXXXXX.ouHdm2P4/terraform_1.3.1_darwin_amd64.zip
  inflating: /usr/local/Cellar/tfenv/3.0.0/versions/1.3.1/terraform  
Installation of terraform v1.3.1 successful. **To make this your default version, run 'tfenv use 1.3.1'**
Enter fullscreen mode Exit fullscreen mode

List down all the installed terraform again:

tfenv list         
* 1.3.1 (set by /usr/local/Cellar/tfenv/3.0.0/version)
  1.2.7
Enter fullscreen mode Exit fullscreen mode

You can see that the latest version is selected now.

If you'd like to switch to the old version, you simply run:
tfenv use VERSION

So:

tfenv use 1.2.7

Now you can see the default selected version:

tfenv use 1.2.7
Switching default version to v1.2.7
Default version (when not overridden by .terraform-version or TFENV_TERRAFORM_VERSION) is now: 1.2.7
➜  ~ tfenv list     
  1.3.1
* 1.2.7 (set by /usr/local/Cellar/tfenv/3.0.0/version)
Enter fullscreen mode Exit fullscreen mode

This way you can test the newer version in your dev codebase in an easy way with just switching versions.

I hope you enjoyed this short blog.

Thank you for reading!

Top comments (1)

Collapse
 
grootnocode profile image
Mike Tyson of the Cloud

With Brainboard, managing different terraform versions is easily manageable. Give it a try!

Find and follow new tags! πŸ€” Did you know? Β  DEV has a variety of tags to help you find the content you like. Find and follow your favorite tags