Mastodon
Select Page

So any DevOps engineer who has worked with Terraform for a while has heard of Modules. Generally, they are similar to a function in programming. You can have something that you need to do multiple times with maybe a slight variation of variables and you can just keep re-using it. The main added benefit is that each module can have it’s own version which just allows for a little bit more control over various updates.

In this post I wanted to cover some of the general use cases that I have found Terraform Modules to be useful and how they can be leveraged in different ways with different cases to provide a fully featured system.

Consultancy

Whenever I am managing various cloud environments for different clients there are some baselines that I enjoy having set up. AWS Config, GuardDuty, Logging, etc. Rather than constantly copying the same chunk of Terraform code to every single client I can create a single Base Line config that allows me to quickly configure these. Then as there are updates to things I can make the updates and quickly apply it across my clients.

Overall this has helped to save a significant amount of time and really just helped to make things a little smoother. It is also super helpful whenever things can remain mostly consistent for a baseline which allows me to work faster on setting other systems up.

Internal

Let’s be real. There is that one weird config that you have to create that only really applies to your company. Ultimately this is a great opportunity for an internal Terraform Module. This allows you to have a function to deploy something weird consistently. It also allows the opportunity to manage things more generally. This also allows the ability to control the general implementation of everything. By that it means that it removes the potential for people to be constantly tweaking things and causing a thousand different versions being deployed and none of them working in the intended manner.

Repeatability

After some amount of time I know that I have found I am deploying the same blocks of TF code. This really just means that I am constantly copying the same chunk and slightly editing it for ports or something. This is something where I have found even a small module that does something super simple helps to save me a lot of time especially when a resource gets an update.

Final Thoughts

Overall Terraform Modules are a fantastic construct within the Infrastructure as Code paradigm. It allows for the repeatability side of things to be very true. I do think there is the potential to overdo it on modules, but overall even small modules that help to save time I think are valid.