In a previous article, I presented to you coding-style importance and pre-commit framework. Today, we’re going to handle pre-commit for Terraform code. It will be in charge of validating code using linters and scanners. For any new git commit, we’ll be able to ensure there is no regression and keep a constant quality.

First of all, we’ll create a Terraform module for having something to test. The modules are good to not duplicate code and should be hardly tested to be reliable. We’ll have a look at which pre-commit plugins to use for Terraform.

Once the module in place, we’ll produce a Docker image for pre-commit. The goal is to have a portable and ready-to-use toolbox for the CI/CD using Circle CI. The Terraform module will have also its own Circle CI project and reuse the image for testing.

Terraform Module Example

Terraform module is perfect to factorize code. In this context, continuous testing makes perfect sense. As an example, we’re going to code a module to configure networking in AWS.

#docker

Produce Reliable Terraform Code With Pre-Commit Hooks
1.45 GEEK