Skip to main content
DevOps Tools

Terraform Formatter

Paste Terraform/HCL code and get it cleanly indented and consistently formatted.

Paste your Terraform (HCL) code below - this tool re-indents blocks and normalizes spacing around the common patterns HCL uses.

For guaranteed byte-for-byte output matching HashiCorp's own tool, `terraform fmt` in your own environment remains the authoritative formatter.

What Does This Tool Do?

It re-indents nested HCL blocks (like resource, variable, and provider blocks) consistently and normalizes spacing around = assignments, similar in spirit to what terraform fmt does locally.

Why Use This Tool?

Useful for quickly cleaning up HCL pasted from elsewhere (a chat message, a ticket, an AI-generated snippet) into consistent formatting before you paste it into your own project.

How to Use It

  1. Paste your Terraform/HCL code.
  2. Click Format.
  3. Copy the cleanly formatted result.

Limitations

This handles common, well-formed HCL structure - severely malformed input (mismatched braces/quotes) is reported clearly rather than silently corrupted, since guessing at broken syntax could produce misleading output.

Example

resource "aws_s3_bucket" "logs" {
bucket="acme-logs"
  tags={
      Environment="prod"
  Team = "platform"
  }
}

becomes:

resource "aws_s3_bucket" "logs" {
  bucket="acme-logs"
  tags={
    Environment="prod"
    Team = "platform"
  }
}

Indentation and nesting are fixed; spacing inside each line is kept as you wrote it. To also normalise spaces and align the = signs in a block, run terraform fmt locally.

Formatting in Your Workflow

  • Locally: terraform fmt -recursive formats every .tf file in the project.
  • In CI: terraform fmt -check -recursive fails the build if anything is unformatted - add it next to terraform validate.
  • In the editor: the official HashiCorp extension for VS Code formats on save.

Formatting Is Not Validation

Well-formatted HCL can still reference a variable that does not exist or use the wrong argument name for a resource. After formatting, run terraform validate and terraform plan to catch real errors before anything is applied.

Start new configurations with the Terraform Configuration Generator, and tag resources consistently with the Cloud Tag Generator.

Frequently Asked Questions

It applies similar indentation and alignment in your browser for quick cleanup. terraform fmt is the official formatter and should be used in your workflow or CI for exact results.

No. Formatting only changes whitespace and alignment - resources, values and behaviour stay exactly the same.

No. Formatting happens entirely in your browser.
Share this tool: