Evan Borgstrom

Principal Engineer at NerdWallet and Python developer since the early 2000's. Over the past 15 years Evan has used Python for everything from CLI tools, to high volume event driven HTTP APIs, to serial TTY protocols for controlling hacked up electronic knitting machines.

Python + Terraform = ♥

DevOps, Testing, & Automation, Advanced
8/17/2019 | 1:30 PM-2:00 PM | Fisher West

Description

At NerdWallet we are heavy Terraform users, but we don't use HCL (the native Terraform language) to build our resource definitions -- we use Python! This talk will cover the motivation for using Python and details of the implementation of how Python is converted into Terraform definitions.

Abstract

Terraform is an amazing tool. Like, really amazing. When working with code that is managing third-party service definitions, and actually applying changes to those definitions by invoking APIs, a high-degree of confidence in the change process is a must-have, and that's where Terraform excels. The work flow it empowers allow teams to quickly make changes across a large (and ever growing) footprint in multiple providers/regions/technologies/etc.

But as your definitions grow the HCL syntax very quickly leaves a lot to be desired, and oh-my-gosh is it verbose... So many definitions of variables and outputs need to be repeated, over and over, as you compose more modules that use each other. Also, since HCL is a language built at Hashicorp specifically for Terraform it has an immaturity about it that is just the fact of the matter about a young language.

Nestled in the Terraform docs there is a section on a JSON syntax. Well... building JSON from code is something we're pretty good at in Python!

At NerdWallet we have built a custom Python abstraction that allows us to build Terraform definitions in a manner that feels very similar to HCL, so that we can apply examples from the documentation, while still giving us the full power of Python to do more complicated data manipulations & transformations.