gavd.co.uk

Frail and faltering follower of Jesus

Test driving tfenv Terraform version manager

By Gavin Davies

Based on Ruby’s rbenv, tfenv is a “Terraform version manager”.

In short, this means you can have multiple versions of Terraform installed on your computer and tfenv will automatically select it, and even install it if it’s not present:

tfenv will use the terraform version from the current directory, or its nearest parent. You can even have a structure like this:

File Contents
./.terraform-version 0.12.0
./foo/.terraform-version 0.12.1
./foo/bar/.terraform-version 0.12.2

Created using something like this:

$ mkdir x
$ cd x
x $ echo 0.12.0 > .terraform-version
x $ mkdir foo
x $ cd foo
x/foo $ echo 0.12.1 > .terraform-version
x/foo $ mkdir bar
x/foo $ cd bar
x/foo/bar $ echo 0.12.2 > .terraform-version

then you can verify the versions:

➜  bar terraform --version
Terraform v0.12.2

Your version of Terraform is out of date! The latest version
is 1.2.8. You can update by downloading from www.terraform.io/downloads.html
➜  bar cd ..
➜  foo terraform --version
Terraform v0.12.1

Your version of Terraform is out of date! The latest version
is 1.2.8. You can update by downloading from www.terraform.io/downloads.html
➜  foo cd ..
➜  x terraform --version
Terraform v0.12.0

Your version of Terraform is out of date! The latest version
is 1.2.8. You can update by downloading from www.terraform.io/downloads.html

Nice! It’s using the correct version in each case.

Any good?

I’ve been running with it for about 3 weeks, and honestly it’s worked like a dream. It’s taking care of all version switching for me.

It’s particularly good if you’re doing migrations!

Getting tfenv

To get TFEnv, head to tfutils/tfenv on Github!

What about Terragrunt?

There is also a tgenv, which is basically the same thing but for Terragrunt.