Member-only story

The ‘best’ way to format and structure Terraform code?

Jack Roper
3 min readAug 27, 2020

--

Over the past year, I’ve been delving deeper into Terraform, using it in anger to deploy resources on Azure and AWS, working on multiple projects. A few weeks into my journey, I was wondering…just how should this stuff be laid out, formatted and structured? There is no clear answer of course as with everything in code and tech, but there are some ‘best practice’ guidelines.

This article doesn’t touch on all best practices around Terraform (e.g. for those familiar with Terraform, multiple workspaces, terraform remote state, using terraform cloud, etc.), but focuses on configuration file layout and structure.

Use the ‘terraform fmt’ command

This command when run against your terraform files formats everything into a standard format and style, providing consistency across files and projects. More info here: https://www.terraform.io/docs/commands/fmt.html

Standard file naming and structure across projects and modules

I was involved recently in creating a standard customer landing zone in Azure, a concept in which a standard set of resources could be deployed into an Azure subscription, giving the customer a base to run workloads in Azure. Microsofts Cloud Adoption Framework (CAF) program has…

--

--

Jack Roper
Jack Roper

Written by Jack Roper

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

No responses yet