Terraform / HCL Formatter
Paste Terraform or other HCL and get consistent two-space indentation with the equals signs aligned in runs of attribute lines, in the style of terraform fmt.
Use the tool
Why this tool exists
Terraform code pasted from a blog, a chat or an older module rarely follows the layout that terraform fmt produces. Reviewers then spend time on whitespace instead of logic, and a CI check that runs fmt fails the pull request. If you are on a machine without Terraform installed, you cannot fix it on the spot.
This formatter handles the two things people see most: nesting indentation and alignment of consecutive attributes. Heredoc bodies are copied exactly. It is text-based and approximate, so treat terraform fmt as the final word in your pipeline.
How to use it
- Paste your Terraform or HCL code into the input.
- Read the formatted output, with nested blocks indented by two spaces.
- Copy it back into your .tf file.
Frequently asked questions
Is the output identical to terraform fmt?
It follows the same main rules, indentation by depth and aligned equals signs, but it is a text-based approximation. Edge cases such as complex expressions may differ, so run terraform fmt in CI as the reference.
What happens to heredocs?
Everything between a heredoc start such as EOT and its closing marker is copied unchanged, so embedded scripts and JSON policies keep their original spacing.
Does it validate my configuration?
No. It does not parse the language or check resource arguments, provider schemas or references. Use terraform validate for that, and terraform plan to see what a change would do.
Are comments kept?
Yes. Hash and double-slash comments stay on their lines and are indented with the block they sit in. Brackets inside strings and comments are ignored when counting depth.