Member-only story

TDD for Terraform IaC — Introducing t2d2

Sahu
5 min readMar 1, 2022

--

Gokarna, India — photosbysaurav on Instagram

“Testing Infrastructure as Code should be as easy as testing Application Code”

I began my Cloud journey in college, working on one of the projects for our Labs. It was a Xamarin Mobile Application which helped friends split expenses and the contacts were brought in through your Facebook Connections. It was the first time I used any Cloud Service Provider for hosting the backend APIs and using an Authentication Provider (Azure Active DIrectory in this case).

The process of setting up these services, at least, for me, was a little unclear as I was doing a lot of trial and error. But things did work at the end.

Infrastructure as Code has become the standard way of provisioning resources in the cloud these days, and as such, tools like Terraform, Amazon CDK and Pulumi, and obviously countless others have boomed in their popularity. And rightfully so, as long as things can be versioned and maintained in source control; and can be tested — they’re the best way to create infrastructure.

Writing Infrastructure as Code A.K.A IaC

As mentioned above, there are lots of different ways to go about IaC, and each have their reasoning for approaching it the way they have. I personally like Terraform, as it is declarative and has a fairly simple language construct.

Testing IaC

As with Application Development, Infrastructure should also contain tests to validate various aspects of said Infrastructure written as code. There are blogs about this and I’d recommend going through Rohit’s Terraform Testing Comparison blog.

As the blog goes on to say, there are various tiers of Infrastructure that you’d want to test. Few of them, already built into Terraform and then few more can be done from the plethora of libraries out there.

I come from an application development background and want to approach IaC testing with the same set of tools and construct that make web development fun, TDD.

Introducing T2D2

I’m happy to announce the first public preview of T2D2 — an abbreviation of ‘Terraform Test Driven Development’ — which is a TypeScript library to help you write IaC tests in TypeScript…

--

--

Sahu
Sahu

Written by Sahu

All opinions shared are personal and not influenced by my Employer • Senior Software Engineer @ McKinsey & Company

No responses yet

Write a response