Make your DevOps life a little easier

Further to ‘3 Tools to Make Your Terraform Life Easier’, I thought I’d highlight some lesser known free software tools that have helped me over the years working with infrastructure as code.

All these tools can be used on any Linux distro and Mac OS X.

First off…

OK, so this is not a lesser known tool…nor is it a tool! Worth mentioning though, as I often come across people who haven’t heard of it. It’s the base that makes everything easier, quicker and cool.

It’s an excellent framework for managing Zsh shell configuration. It supports plugins and themes that just make terminal/CLI work a lot smoother. My core tools at the time of writing are Terraform, AWS CLI, Python with virtualenv and Kubernetes based things (docker, kubectl, helm etc.).

Once installed, you can specify the plugins and theme you want in your ~/.zshrc file. Here’s what I use:

ZSH_THEME="agnoster"
plugins=(
  git
  aws
  pip
  python
  terraform
  virtualenv
  virtualenvwrapper
  docker
  kubectl
  helm
  minikube
  zsh-autosuggestions
)

Be careful how many plugins you use. It can start to slow your terminal down if there are too many. And if you use the agnoster theme (and why wouldn’t you? Just look at it…it’s beautiful!) you may need to install some fonts on your machine and configure your terminal app (I use iTerm2 on my Mac):

Now that you have a Zsh shell that looks pretty, you can play around with what you can do with your chosen plugins. The main advantages are command line completion and your command prompt, which of course can be customized to your heart’s content. I like to keep mine reasonably simple.

It’s very handy having some shortcuts like asp to switch between AWS CLI profiles (if you have some set up) and using double tab to show all the options available for some of the commands you have plugins for. A quick video below to show some examples and how the command prompt changes depending on your setup:

If you decide to use it, then consider showing them some love by buying their merch.

Virtualenv Wrapper

It’s basically Python virtual environment for lazy people. After installation, just set the following in your user profile somewhere:

export VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3
export VIRTUALENVWRAPPER_VIRTUALENV=/usr/local/bin/virtualenv
export WORKON_HOME=~/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

Then you can use the following commands to create, use and destroy Python virtual environments:

Create a virtual environment:

mkvirtualenv my-project-venv

List all virtual environments:

lsvirtualenv

Use a venv or switch to it:

workon my-project-venv

Come out of the virtual environment:

deactivate

Delete a virtual environment

rmvirtualenv my-project-venv

And if you have oh my ZSH installed, and the virtualenv plugin, command auto completion should work, and you can see what else you can do by referring to the plugin documentation.

Stern

As described on their github readme page:

Stern allows you to tail multiple pods on Kubernetes and multiple containers within the pod. Each result is color coded for quicker debugging.

Instead of me trying to explain how it works, this short video says it all:

Terraform-docs

Terraform-docs is a powerful utility to generate documentation from Terraform modules in various output formats.

It is very well documented and is a tool that helps me make my Terraform modules have great readmes. Give it a go!

Make sure all your Terraform variables are well formed with meaningful descriptions, and types. After installation, run:

terraform-docs markdown .

You’ll see some lovely markdown output to your terminal. That should obviously be redirected to a readme file or wherever you wish.

Here’s an example.

If you decide to use Terraform-docs, you should look to incorporate it into your automated workflow somehow. Either into your code development workflow for your Terraform modules (perhaps a pre or post commit hook) or into your CI/CD pipeline if that makes more sense.

I first came across this tool when working with Cloud Posse’s build-harness. They do some very cool things with Terraform, so check out their stuff.


Written by Vishal Bhalla, Airwalk Reply Senior DevOps Engineer

Please get in touch if you’d like to discuss this article further with Vishal.