How to keep your terraform code clean and robust (Part1)?

Mohamed Dhaoui
12 min readDec 5, 2022

In this series of articles, we will explore best practices for writing, validating and testing a terraform Code.

Terraform is one of the most used tools in the IaC space that enables us to safely and predictably apply changes to our infrastructure. Terraform uses HCL (Hashicorp Configuration Language) to configure the target infrastructure requirements.

Once the infrastructure is configured, Terraform downloads the required plugins from the registry which are then used to call respective cloud platform APIs to provision the target state. While doing so, Terraform also records the mapping between the configuration and the resources created in a state file.

Starting with Terraform can feel like an intimidating task at first, but a beginner can quickly reach a basic understanding of the tool. After the initial learning period, a new user can start running commands, creating and refactoring Terraform code. After learning the basics, many users face nuances and issues around how to validate and test locally their code , how to make it robust against typing mistakes, how to validate the used configuration and how to keep a good quality level with the smallest of effort?

In this article, we will try to respond to these questions! We will list a few tools and practices that will…

--

--

Mohamed Dhaoui

Lead Data engineer and Data science practitioner ! Interested in data science and software development topics. GCP 5x certified and Go fan.