Terraform HCL Formatter
Format Terraform HCL with canonical style — matches terraform fmt, nothing sent to any server
Terraform’s HCL syntax is readable by design, but inconsistent formatting across team members makes code reviews harder than they need to be. terraform fmt standardizes style — but requires Terraform installed locally. This tool formats your HCL code in the browser with the same rules, so you can clean up snippets, review formatting, or format files on machines without Terraform installed.
What Gets Formatted
The formatter applies Terraform’s canonical style rules:
- Indentation — 2-space indentation for all block nesting levels
- Alignment —
=signs aligned within blocks for readability - Spacing — Consistent spacing around operators, after commas, and between blocks
- Block ordering — Blank lines between top-level blocks
- Quotes — Normalized quote style for strings
- Trailing commas — Consistent handling in lists and maps
- Heredoc — Proper indentation of heredoc content
When This Tool Helps
- Code reviews — Format a snippet from a PR without cloning the repo
- Documentation — Clean up HCL examples for README files and wikis
- Quick edits — Format on a machine without Terraform installed
- Learning — See how Terraform expects HCL to look
How to Use
- Paste your Terraform HCL code into the input editor
- The formatted output appears instantly
- Copy the formatted code back to your project
Terraform vs HCL
HCL (HashiCorp Configuration Language) is the syntax — Terraform is one of several tools that use it. This formatter follows terraform fmt conventions specifically. Other HCL-based tools like Packer and Nomad use the same base syntax but may have different conventions.
Example
Before formatting:
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
tags = {
Name = "web-server"
Environment = "production"
}
}
After formatting:
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
tags = {
Name = "web-server"
Environment = "production"
}
}
Notice the consistent 2-space indentation and aligned = signs within each block.
Frequently Asked Questions
Does this match terraform fmt output exactly?
The formatter applies the same canonical style rules as terraform fmt. For standard HCL constructs, the output is identical. Edge cases with complex expressions or unusual heredoc patterns may differ slightly.
Can it format Terragrunt files? Terragrunt uses HCL syntax with additional functions and blocks. Basic HCL formatting works, but Terragrunt-specific constructs may not be handled perfectly.
Does it validate my Terraform code?
This tool focuses on formatting, not validation. It won’t catch resource misconfigurations or provider errors — use terraform validate for that.
Is my code sent to a server? No. All formatting runs in your browser using JavaScript. Your Terraform code never leaves your device.