Terraform Best Practices — Testing your code

Jack Roper
CodeX
Published in
4 min readApr 19, 2021

--

When starting out with Terraform it’s hard to know what is considered ‘best practice’ in a number of areas.

This post is the last in the series which focuses on point 9 in the list, ‘Test your code’.

  1. Use a consistent file structure across your projects.
  2. Use modules wherever possible.
  3. Use a consistent naming convention.
  4. Use a consistent format and style.
  5. Hold your state file remotely, not on your local machine.
  6. Avoid hardcoding variables.
  7. Fewer resources in a project are easier and faster to work with.
  8. Limit resources in the project to reduce the blast radius.
  9. Test your code.

Overview

As greater resiliency is required and more varied infrastructure is introduced, testing code leads to greater confidence that the code will perform as expected.

A combination of tools can be used to perform different types of testing to provide wider code coverage.

  • Integration Testing
  • Unit Testing
  • Compliance Testing
  • End-to-end Testing (E2E)

--

--

Jack Roper
CodeX
Writer for

A blog about DevOps & Cloud Tech. Specializing in Terraform, Kubernetes, Azure & Azure DevOps! ☁️