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.
More DevOps Tools
View all 16For 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
- Paste your Terraform/HCL code.
- Click Format.
- 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 -recursiveformats every.tffile in the project. - In CI:
terraform fmt -check -recursivefails the build if anything is unformatted - add it next toterraform 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
Explore More Tools
Keep going with related categories and our most used tools.