Ad space (banner)
AD

Got the fundamentals? A structured Terraform course is a fast way to level up.

Find Terraform courses on Udemy

Affiliate link. Costs you nothing extra.

Lesson 9 / 37

Formatting Code with terraform fmt

When you want consistent formatting, use terraform fmt. It rewrites configuration files into the canonical style.

The syntax is terraform fmt. Add -recursive to include subdirectories, or -check to verify without changing anything.

Running it reformats indentation and alignment, printing the name of every file it changed — and nothing at all when everything is already tidy.

A common stumble is arguing about formatting in code review. With fmt there is one correct answer, so the argument disappears.

In real work, fmt -check runs in CI to keep the whole repository consistent automatically.

Terraform
Try it (type this into the pseudo terminal)
terraform fmt

🧑‍💻 You can type this command into the Terraform pseudo terminal to try it yourself (this page itself has no interactive terminal).

Ad space (banner)
Ad space (in-article)