Loading HCL Formatter...
Please wait a moment

How to Format HCL - Step by Step Guide

Step 1

Input Your HCL/Terraform Configuration

Let's get your HCL (HashiCorp Configuration Language) into the formatter! Whether you're working with Terraform infrastructure code, need to format Terraform modules, or want to beautify your configuration files, you have several convenient options:

•
Paste directly: Copy your Terraform configuration or HCL code and paste it into the input editor
•
Upload a file: Click "Upload" to select a .tf, .hcl, or .txt file from your computer
•
Try the sample: Click "Sample" to load example Terraform configuration and see how the formatter works

Example: Unformatted HCL Input

A typical file after a few rounds of copy and paste, with indentation all over the place:

resource "aws_instance" "web" {
ami = "ami-123456"
      instance_type = "t2.micro"


    tags = {
Name = "WebServer"
  Environment = "prod"
        }
}
Step 2

Automatic Formatting & Validation

About half a second after you stop typing, the page reads your HCL configuration and:

•
Checks the syntax: Uses hashicorp/hcl, the parser Terraform itself uses. If the file can't be read, you see the line and column of the first problem instead of output
•
Re-indents every line: Two spaces per level, so nested resources and blocks are easy to follow. Strings, heredocs and comments are left exactly as written
•
Syntax highlighting: Color-codes different elements for better readability

Example: Beautifully Formatted Output

The same configuration as it comes out of the formatter. Only the indentation and blank lines changed:

resource "aws_instance" "web" {
  ami = "ami-123456"
  instance_type = "t2.micro"

  tags = {
    Name = "WebServer"
    Environment = "prod"
  }
}
Step 3

Choose a Layout

There are two layouts to pick from:

•
Pretty format: Default beautified HCL with proper indentation (2 spaces)
•
Minify: Click "Minify" to drop indentation and blank lines. Lines are never joined, because HCL ends each argument at a line break
•
Syntax highlighting: Terraform-specific syntax colors make code easier to understand
Step 4

Export Your Formatted HCL

Take the result back to your project or your DevOps workflow:

•
Copy to clipboard: One-click copying for quick pasting into your code editor or terminal
•
Download as file: Save as a .tf file for use in your Terraform projects
•
Valid HCL badge: Shown only when the parser accepted the text currently in the editor. It checks syntax, not provider rules, so still run terraform validate before applying

Frequently Asked Questions

How do I format messy Terraform/HCL configuration?

Paste it into the editor or upload the .tf file. About half a second after you stop typing, every line is re-indented with two spaces per level of braces, brackets or parentheses, trailing spaces are removed and runs of blank lines shrink to one. Nothing else on the line is touched.

Will formatting change my values, strings or heredocs?

No. Only the whitespace at the start and end of a line changes. Quoted strings, ${...} interpolations, numbers such as 8901240544102066246 or 14.50, and comments stay exactly as you typed them, and heredoc bodies (<<EOF and <<-EOT) are copied byte for byte, including their own indentation. Before showing the result, the page reads both versions with the HCL parser and checks they say the same thing; if they ever differed, you would get your file back unchanged with a note.

Does the formatter validate Terraform syntax?

It checks the syntax with hashicorp/hcl, the same parser Terraform uses, compiled to run in your browser. If the file cannot be read, you get the line and column of the first problem instead of a formatted copy. It does not know about providers, so an unknown resource type or a misspelled argument still passes; terraform validate catches those. The HCL Validator page shows more detail about errors.

Is the output the same as terraform fmt?

Not exactly. Both use two-space indentation, but terraform fmt also lines up the equals signs of neighbouring arguments and tidies spacing inside a line, which this page does not do. Run terraform fmt afterwards if your CI checks for its exact layout; it will only adjust spacing.

What does the Minify button do?

It removes indentation and blank lines so the file takes up fewer lines, which is handy for pasting a block into a chat or a ticket. HCL ends each argument at a line break, so lines are never joined together, and heredocs and comments are kept as they are. Editing the input switches back to the normal layout.

Is my configuration uploaded anywhere?

No. Parsing and formatting both happen in your browser, so nothing you paste or upload is sent to a server. That matters for Terraform files that hold account IDs or other details you would rather keep private. Very large files can take a moment, because the parser runs on your own machine.

For a closer look at errors, open the HCL Validator, or turn the file into JSON with HCL to JSON.