Converters

Terraform / HCL Formatter

Format and validate Terraform HCL code with consistent indentation, aligned assignments, and syntax checking.

Paste HCL code and click Format & Validate

What Is an HCL / Terraform Formatter?

HCL (HashiCorp Configuration Language) is the declarative language used by Terraform, Packer, Vault, Consul, and other HashiCorp tools to define infrastructure as code. An HCL formatter takes messy or inconsistently styled Terraform code and reformats it with proper indentation, aligned assignments, and consistent spacing — similar to what terraform fmt does locally.

Consistent formatting isn't just cosmetic. It makes Terraform configurations easier to review in pull requests, reduces merge conflicts caused by whitespace differences, and helps teams enforce coding standards. Misaligned assignments, inconsistent indentation, and irregular spacing make it harder to spot actual changes in code reviews.

This online HCL formatter processes your Terraform code entirely in the browser — no installation, no CLI, no server. It handles resource blocks, variables, outputs, locals, providers, and nested blocks with proper indentation and attribute alignment. It also validates brace and bracket matching to catch common syntax errors before you run terraform plan.

How to Format Terraform Code Online

  1. Paste your HCL code — Copy your Terraform configuration into the editor, or click one of the sample templates (AWS EC2, Azure Resource Group, GCP Compute, Variables & Outputs) to load example code.
  2. Click "Format & Validate" — The formatter will reindent your code, align assignment operators within blocks, and check for unmatched braces or brackets.
  3. Review the diff — Switch to the "Diff" tab to see exactly what changed. Added lines are highlighted in green, removed lines in red.
  4. Copy the formatted output — Click "Copy Formatted" to copy the clean code to your clipboard, ready to paste back into your editor.

Key Features

  • Assignment alignment — Aligns the = signs within blocks so attributes line up vertically, matching Terraform's official style.
  • Syntax validation — Detects unmatched braces and brackets before you run terraform validate, saving you a CLI round-trip.
  • Diff view — See a line-by-line diff of what changed, so you can review formatting adjustments before applying them.
  • Sample templates — Load pre-built examples for AWS, Azure, GCP, and variable/output blocks to quickly test the formatter.
  • Heredoc preservation — Heredoc blocks (<<EOF) are preserved as-is, without reformatting their contents.
  • 100% client-side — Your infrastructure code never leaves your browser. No server, no uploads, no tracking.

Common Use Cases

  • Pre-commit formatting — Format Terraform files before committing when you don't have terraform fmt installed locally.
  • Code review preparation — Clean up formatting before opening a pull request to keep diffs focused on actual logic changes.
  • Learning Terraform style — See how properly formatted HCL should look with aligned attributes and consistent indentation.
  • Quick validation — Catch unmatched braces or brackets in your Terraform code without running the CLI.
  • Cross-cloud formatting — Format AWS, Azure, and GCP Terraform configurations with the same consistent style.

Frequently Asked Questions

🔒 This tool runs entirely in your browser. No data is sent to any server.