3 Tools to Make Your Terraform Life Easier

Overview

 

It is indisputable to say that HashiCorp Terraform has become an essential tool in Cloud deployment. At the same time, it also got its own limitation. Have you ever encountered the following issues? Incompatible Terraform version when you tried to plan/apply the tf scripts written by you other team members, Terraform output is lengthy and difficult to read, got a problem in switching between several AWS identities when planning/applying different project works.

Fortunately, the community has got some open source tools which will make your life with Terraform easier. I hope you will find them useful.

tfenv

tfenv is a Terraform version manager which not only installs the needed Terraform version on the fly but also enables you to switch to the desired Terraform version between multiple environments. It saves your effort to change soft links to needed Terraform binaries. All you need is to tell tfenv to install needed Terraform versions before hand and specify your desired Terraform version in the .terraform-version file in your different project directories. Then you are ready to go and the appropriate version of Terraform will be invoked.

 

Terraform Landscape

Terraform Landscape is a tool for reformatting the output of terraform plan to be easier to read and understand. A picture is worth a thousand words.

Before
Before
After
After

direnv

This 3rd tool comes handy when used with tfenv. direnv is an extension for your shell. It augments existing shells with a new feature that can load and unload environment variables depending on the current directory. For instance, you have developed multiple project works and they are sitting in different directories. Previously, you will need to reset the AWS credentials in UNIX Shell environment variables each time you switched between development project and staging project and have Terraform read from these variables to assume the appropriate AWS IAM role. This environment variable setup is per UNIX shell session basis and is prone to typing error. With the use of direnv, you can preset the credentials in a per project per directory basis. Everytime you change directory to a particular project, this tool will load the correct variable values for your Terraform. And when you leaves that project directory, these variables will be unloaded. It is pretty convenient as you don’t need to change the variable value time after time.

 

These tiny tools don’t make any big difference to my delivery output but they definitely increase my productivity.