9 Extraordinary Terraform Best Practices That Will Change Your Infra World

Tiexin Guo
GitGuardian
Published in
13 min readApr 12, 2022

--

Before you quickly glance over the title and think “Oh god, yet another tutorial on how to give proper names to variables, how to use modules, how to manage states; nothing I haven’t already know” then close the tab right away, let me assure you this: this article is none of those.

This “best practices” article aims to tell you something you haven’t read a hundred times. This article won’t give you the answer to everything because there isn’t one right answer that fits all. It aims to make you think about your unique situation and make the best decisions in accordance.

Without further ado, let’s start with writing Terraform code:

1 Clean Code

No tool or programming language is perfect, and Terraform is no different. It has limitations.

For example, for old Terraform users from 0.12 or even earlier age, you might remember that before Terraform 0.13, you can’t even use for_each for modules. In August 2020, with the release of Terraform 0.13, HashiCorp finally introduced the ability to loop over modules with a single module call.

Once you have accepted the quirks and features, you can utilize a bunch of best practices to organize your code and to use it better. Even though Terraform…

--

--