Getting Started with Terratest on Azure

Brendan Thompson • 10 June 2021 • 2 min read

In the brave new world of Infrastructure-as-Code (IAC) engineers are making changes to their infrastructure codebase potentially many times a day, one thing that is often overlooked by engineers typically from a System Administration background is testing. Testing is a fundamental piece in Software Engineering and something that prevents myriad of problems, so why are we not applying this to IAC?

If you happen to be using Terraform as your IAC-of-choice then you're in luck, there are a few different ways that you can perform testing on the code you're writing, my favorite way to deal with this is using Terratest a product written by the people over at Gruntwork this allows engineers to run integration testing on the IAC. Meaning, that when there is a change to the code, lets say for a module, before that module is released and/or consumed we can validate that our changes have not introduced any issues or bugs, it is also a good way to validate that your module fulfills any requirements that you might have.

In this post we will go through how to get started with Terratest, and how it can be used to test a simple Azure module. We will be using GitHub Actions as our orchestrator for running the tests as well as showing how these tests could be used as a checkpoint/gate for Pull Requests.

Installation & Setup#

First of all we will need to setup our environment so that we can start testing. In this you will need the following things:

  1. Your favorite code editor
  2. A basic understanding of Terraform and Golang
  3. Access to Terraform Cloud (there is a free tier)
  4. A GitHub repository with GitHub Actions
  5. An installation of Golang and Terraform in your development environment

Brendan Thompson

Principal Cloud Engineer

Azenix

Discuss on Twitter