Skip to main content
Presentation

Testing your HCL Modules in Terraform

Terraform modules are being written to handle multiple conditions on given data or differing environments. Just like any other code, this HCL config logic should be tested.

Terraform modules are being written to handle multiple conditions on given data or differing environments. Just like any other code, this HCL config logic should be tested.

Some argue that running Terraform against a mock environment is already a functional/acceptance test. You can script to prove that the thing you expected to deploy actually got deployed. There are also frameworks for validating plans or deployments against some constraints. However, there is little in the form of performing unit tests.

This talk covers an automated unit testing process Gareth Brown's team has used to systematically and incrementally test small changes in HCL against expected test results and functionally test the module as a whole in a controlled environment before being released.

What You'll Learn

The talk will demonstrate: - Using a small Python test fixture to verify logic in the module that processes data and returns an expected result - Where to apply logic in a module - How the approach can be applied to a complex, real-world scenario deploying to Google App Engine, Google Cloud Run, and Kubernetes - Running unit tests and functional tests in GitHub Actions

Speaker: Gareth Brown

Slides available here

More resources like this one

3/15/2023Presentation

Advanced Terraform techniques

2/3/2023Case Study

Automating Multi-Cloud, Multi-Region Vault for Teams and Landing Zones

2/1/2023Case Study

Should My Team Really Need to Know Terraform?

1/20/2023Case Study

Packaging security in Terraform modules