Testing IaC Using Gherkin

New IaC testing options are popping up.

Hey folks,

I recently checked out the InfraSpec project. It offers Gherkin syntax to test your Infrastructure as Code (IaC). Two things to note about this project:

  • it is still in heavy development and is likely to change (they call this out in the README)

  • it uses a Fair Core License

But this is still super cool. If you come from the Ruby or Python world, this style of Behavior Driven Development (BDD) testing will look familiar. To learn more about the Gherkin syntax, check out these best practices.

This project is the type of thing we need in IaC to improve quality and maintainability. Using BDD can reduce the barrier to testing.

There are other options, but they have their tradeoffs. A lot of infra engineers don't know how to use Terratest since the tests for that framework are written in golang.

The new testing framework in TF is AWESOME and helps you write both unit and integration tests. But it's also fairly new and hasn't caught on yet.

I have been mentioning the need for good testing options for a while. I wrote about how important testing IaC would be for any new tools:

I want testing to be more of a first class citizen than something that gets bolted on as an afterthought.

I've also talked about how you can set up sandbox environments for devs to test their changes:

Engineers can tf plan and tf apply against [a sandbox] environment from their machines all they want. This offers a "local" environment to test their TF changes against.

To be clear, that kind of ad-hoc testing is useful, but doesn't replace automated tests.

Automated tests prevent regressions and don't rely on human attention.

A strong testing tool like this with more accessible syntax could be a big hit. I hope so, as it can lead to a big quality improvement, benefitting IaC engineers and users everywhere.

Take a look at this this project, keep an eye on the progress, and let's hope it goes from early stage to a common tool ASAP.

May your tests be easy to write,

Matt @ Masterpoint

PS If you’ve found this newsletter helpful, please forward it to a friend. Want to chat through some tricky IaC issue that you or your org are running into? Grab some time on my calendar here.