Skip to content

Formatting

Terraform file formatting helps to ensure that code is easily readable and maintainable. To format all Terraform files recursively in a directory and its subdirectories, run the following command:

terraform fmt -recursive

To format a specific Terraform file, run the following command:

terraform fmt <filename>

fmt in CICD

  • Always format files before committing them to version control
  • Use a pre-commit hook to automatically format files before each commit
  • Include terraform fmt as a build step in your CI/CD pipeline to ensure that all code is consistently formatted
  • Consider using a tool like Terraform Cloud to enforce formatting standards across your team