How To Format Terraform Code With Indentation

This blog post will show you how to format an existing Terraform code with a well readable format and indentation.

Terraform FMT

The Terraform CLI tool comes with a very cool feature that takes an existing code and formats it with the correct indentation.

To try, open an existing Terraform folder with a .TF file and run the following code:

terraform fmt

To fix multiple files you can run the following command at the root of your Terraform configuration files where you have multiple folders and files.

terraform fmt -recursive

To preview the the changes without making any changes you can run the following command.

terraform fmt -check

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.