PureDevTools

Terraform HCL Formatter

Format Terraform HCL with canonical style — matches terraform fmt, nothing sent to any server

All processing happens in your browser. No data is 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:

When This Tool Helps

How to Use

  1. Paste your Terraform HCL code into the input editor
  2. The formatted output appears instantly
  3. 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.

Related Tools

More Docker & DevOps Tools