Terraform Best Practices — Testing your code
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’.
- Use a consistent file structure across your projects.
- Use modules wherever possible.
- Use a consistent naming convention.
- Use a consistent format and style.
- Hold your state file remotely, not on your local machine.
- Avoid hardcoding variables.
- Fewer resources in a project are easier and faster to work with.
- Limit resources in the project to reduce the blast radius.
- 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)