Often we find that Terraform (HCL) modules are being written in a way to be able to handle multiple conditions on given data or differing environments. This demand drives modules requiring logic to be coded into them; and as a result, just like any other code, this logic should be tested.

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

This talk covers an automated process we have for authors of Terraform modules to be able to systematically and incrementally unit test small changes in HCL against expected test results and functionally test the module as a whole in a controlled environment before being released.

The talk will demonstrate:

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

Speaker: Gareth Brown

Some speakers have posted slides here: https://discuss.hashicorp.com/t/hashitalks-2021-speaker-slides/20732

#terraform

Testing Your HCL Modules for Terraform
2.00 GEEK