The Terraform HCL Formatter reformats HashiCorp Configuration Language to the
canonical style that terraform fmt produces — without installing the
Terraform CLI. Paste a .tf file and it returns a tidy version with consistent
indentation and aligned arguments, entirely in your browser.
How it works
HCL has a small set of formatting conventions that the official formatter applies deterministically. This tool reproduces the most impactful ones:
- 2-space indentation for each nesting level. Both
{ }blocks and[ ]collections increase depth. - Aligned
=signs within a contiguous run of single-line argument assignments at the same depth. A blank line, comment, or nested block ends the run, so each group aligns independently. - One space around
=in every assignment. - Collapsed blank lines — any run of two or more blank lines becomes a single blank line, and trailing whitespace is stripped.
The reformatter tracks nesting depth by counting brackets while ignoring those
inside string literals, and it copies heredoc bodies (<<EOT ... EOT)
verbatim so embedded scripts and JSON policies are never disturbed.
Example
Input:
resource "aws_instance" "web" {
ami="ami-123456"
instance_type = "t3.micro"
}
Output:
resource "aws_instance" "web" {
ami = "ami-123456"
instance_type = "t3.micro"
}
Notes and tips
This is a structural reformatter, not the full HashiCorp parser. For most files
the output matches terraform fmt, but for guaranteed byte-perfect formatting
keep terraform fmt -check in your CI pipeline. Because everything runs
locally, it is safe to paste configuration containing backend blocks or
provider settings — nothing is transmitted off your machine.