terraform fmt

The command that rewrites .tf files into Terraform's one standard layout; it never looks at real infrastructure.

In more detail

It fixes indentation to two spaces per level and lines up the equals signs of neighbouring arguments, and there are no options to change the style. With -check it rewrites nothing and exits with a non-zero exit code if any file needs formatting, which is what a pipeline wants. With -recursive it also formats subdirectories such as modules.

Examples

terraform fmt
terraform fmt -check -recursive

Related terms

Taught in

References

Certification courses