BreakingExpress

Manage a number of Terraform variations with tfenv

In my Terraform for Kubernetes beginners article, I used Terraform 11, and in an upcoming article, I will cowl upgrading from Terraform 11 to 12. To put together for that, on this article, I will present you easy methods to use tfenv, a device that makes it a lot simpler to transform from one model to a different, in addition to to handle a number of Terraform variations in your work atmosphere.

Install tfenv

Many coding languages have instruments that permit you to commute between variations based mostly on environmental guidelines. One instance (which tfenv is predicated on) is rbenv, which lets you select which model of Ruby you wish to work with.

tfenv works on Linux, macOS, and Windows; I will cowl the Linux set up utilizing Ubuntu 18.04, however the device’s GitHub repository has installation instructions for the opposite working techniques.

The Linux set up makes use of some Git instructions (try the intro to Git collection when you’re not already aware of it).

First, create a .tfenv folder in your $ listing:

jess@Athena:~$ mkdir .tfenv

Clone the tfenv repository:

jess@Athena:~$ git clone https://github.com/tfutils/tfenv.git ~/.tfenv
Cloning into '/dwelling/jess/.tfenv'...
distant: Enumerating objects: 21, executed.
distant: Counting objects: 100% (21/21), executed.
distant: Compressing objects: 100% (19/19), executed.
distant: Total 1105 (delta eight), reused 10 (delta 2), pack-reused 1084
Receiving objects: 100% (1105/1105), 216.01 KiB | 2.84 MiB/s, executed.
Resolving deltas: 100% (703/703), executed.

If you favor Homebrew, you need to use:

$ brew set up tfenv

Export your path into your Bash profile:

jess@Athena:~$ echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >> ~/.bash_profile

If you wish to use simply the bottom instructions for Ubuntu/Debian-based techniques, there’s an alternative choice that makes issues a bit simpler. After doing the clone within the .tfenv listing, set your profile to place the tfenv command into your profile in your subsequent session:

jess@Athena:~/.tfenv$ . ~/.profile

Once the profile is about, you may symlink your listing to your .native/bin listing to make tfenv an executable binary:

jess@Athena:~/.tfenv$ ln -s ~/.tfenv/bin/* ~/.native/bin

Run the which command, and it’s best to see tfenv‘s location:

jess@Athena:~/.tfenv$ which tfenv
/dwelling/jess/.native/bin/tfenv

How to make use of tfenv

Now that every part is put in, try what instructions can be found:

jess@Athena:~$ tfenv
tfenv 2.Zero.Zero-37-g0494129
Usage: tfenv <command> [<choices>]

Commands:
   set up      Install a particular model of Terraform
   use          Switch a model to make use of
   uninstall    Uninstall a particular model of Terraform
   record         List all put in variations
   list-remote  List all installable variations

As you may see, it is a fairly easy device that lets you set up and uninstall Terraform variations as wanted.

Before you resolve what to put in, test which variations can be found. This is a small snippet, because the record is a few mile lengthy:

jess@Athena:~$ tfenv list-remote
Zero.14.Zero-beta1
Zero.14.Zero-alpha20201007
Zero.14.Zero-alpha20200923
Zero.14.Zero-alpha20200910
Zero.13.5
Zero.13.four
Zero.13.three
Zero.13.2
Zero.13.1
Zero.13.Zero
Zero.13.Zero-rc1
Zero.13.Zero-beta3
Zero.13.Zero-beta2
Zero.13.Zero-beta1
Zero.12.29
Zero.12.28
Zero.12.27

Install Terraform variations

To set up the most recent model of Terraform:

jess@Athena:~$ tfenv set up newest
Installing Terraform v0.13.5
Downloading launch tarball from https://releases.hashicorp.com/terraform/Zero.13.5/terraform_0.13.5_linux_amd64.zip
###################################################################################################################################################################################### 100.Zero%
Downloading SHA hash file from https://releases.hashicorp.com/terraform/Zero.13.5/terraform_0.13.5_SHA256SUMS
No keybase set up discovered, skipping OpenPGP signature verification
Archive:  tfenv_download.N3bzZ2/terraform_0.13.5_linux_amd64.zip
  inflating: /dwelling/jess/.tfenv/variations/Zero.13.5/terraform  
Installation of terraform v0.13.5 profitable. To make this your default model, run 'tfenv use Zero.13.5'

To set up a particular Terraform model (on this case, Zero.12.29):

jess@Athena:~$ tfenv set up Zero.12.29
Installing Terraform v0.12.29
Downloading launch tarball from https://releases.hashicorp.com/terraform/Zero.12.29/terraform_0.12.29_linux_amd64.zip
###################################################################################################################################################################################### 100.Zero%
Downloading SHA hash file from https://releases.hashicorp.com/terraform/Zero.12.29/terraform_0.12.29_SHA256SUMS
No keybase set up discovered, skipping OpenPGP signature verification
Archive:  tfenv_download.1YFOLh/terraform_0.12.29_linux_amd64.zip
  inflating: /dwelling/jess/.tfenv/variations/Zero.12.29/terraform  
Installation of terraform v0.12.29 profitable. To make this your default model, run 'tfenv use Zero.12.29'

Finally, to put in the most recent model of Terraform Zero.11:

jess@Athena:~$ tfenv set up newest:^Zero.11
Installing Terraform v0.11.15-oci
Downloading launch tarball from https://releases.hashicorp.com/terraform/Zero.11.15-oci/terraform_0.11.15-oci_linux_amd64.zip
###################################################################################################################################################################################### 100.Zero%
Downloading SHA hash file from https://releases.hashicorp.com/terraform/Zero.11.15-oci/terraform_0.11.15-oci_SHA256SUMS
No keybase set up discovered, skipping OpenPGP signature verification
Archive:  tfenv_download.8OxQ8k/terraform_0.11.15-oci_linux_amd64.zip
  inflating: /dwelling/jess/.tfenv/variations/Zero.11.15-oci/terraform  
Installation of terraform v0.11.15-oci profitable. To make this your default model, run 'tfenv use Zero.11.15-oci'

That was easy, and now you may put them to make use of!

Change Terraform variations

Once you could have put in a number of variations of Terraform, you may decide one to make use of. First, discover out your choices by itemizing the put in variations:

jess@Athena:~$ tfenv record
  Zero.13.5 (set by /dwelling/jess/.tfenv/model)
  Zero.12.29
  Zero.11.15-oci

By default, tfenv chooses essentially the most up-to-date model of Terraform you could have put in. Find out the default by operating the tfenv use command:

jess@Athena:~$ tfenv use
Switching default model to v0.13.5
Switching accomplished

jess@Athena:~$ terraform --version
Terraform v0.13.5

But what if you must use an older model? This instance switches to the oldest model I’ve put in:

jess@Athena:~$ tfenv use Zero.11.15-oci
Switching default model to v0.11.15-oci
Switching accomplished

jess@Athena:~$ terraform -version
Terraform v0.11.15-oci

Your model of Terraform is out of date! The newest model
is Zero.13.5. You can replace by downloading from www.terraform.io/downloads.html

It’s straightforward as pie! Just run the record command and use the naming conference supplied.

Uninstall Terraform variations

If you could have a model of Terraform you don’t need or want any extra, you may take away it with the uninstall command. For instance, I do not want Terraform model Zero.13:

jess@Athena:~$ tfenv uninstall Zero.13.5
Uninstall Terraform v0.13.5
Terraform v0.13.5 is efficiently uninstalled

To affirm it is not put in:

jess@Athena:~$ tfenv record
  Zero.12.29
  Zero.11.15-oci

Final ideas

The tfenv device is nice for a lot of causes. If you must replace from one model of Terraform to a different, this is likely one of the sooner methods to improve and check the result. If your atmosphere has issues operating on a number of Terraform variations, it is easy to change backwards and forwards as wanted. If you utilize Terraform, strive tfenv and see the way it can rework your atmosphere.

Exit mobile version