Paste HCL and get it formatted like `terraform fmt` — consistent indentation and aligned equals signs.
| Rule | Behavior |
|---|---|
| Indentation | 2 spaces per nesting level, based on brace depth |
| Equals alignment | Consecutive attribute lines at the same depth get their "=" aligned to the same column |
| Blank lines | Multiple consecutive blank lines are collapsed to one |
| Trailing whitespace | Removed from every line |
The Terraform Formatter is a free online tool that automatically formats Terraform configuration files written in HashiCorp Configuration Language (HCL). It applies consistent indentation, spacing, alignment, and block formatting so your Infrastructure as Code (IaC) files are easier to read, review, and maintain.
Whether you're managing a single Terraform project or maintaining hundreds of infrastructure
resources, keeping your code consistently formatted improves collaboration and reduces unnecessary
changes during code reviews. This tool produces formatting similar to the official
terraform fmt command without requiring Terraform to be installed locally.
Simply paste your unformatted Terraform code into the input editor and click Format Code. The formatted output is generated instantly and can be copied directly into your project.
Terraform uses HCL (HashiCorp Configuration Language) to define cloud infrastructure such as AWS, Azure, Google Cloud, Kubernetes, and many other providers. As projects grow, manually maintaining proper formatting becomes difficult.
A Terraform Formatter automatically restructures your configuration while preserving its behavior. It standardizes indentation, aligns assignment operators, organizes nested blocks, and improves overall readability without modifying the logic of your infrastructure.
Because formatting changes only the appearance of the code—not its functionality—you can safely use a formatter before committing changes, creating pull requests, or sharing configuration files with teammates.
The formatter modifies only the presentation of the code. Resource definitions, variables, expressions, modules, outputs, and provider configurations remain functionally identical after formatting.
The formatter can properly organize almost every Terraform block, including:
The following example demonstrates how the Terraform Formatter transforms poorly formatted Terraform code into a clean, consistent, and readable configuration. Notice that the formatting changes only the layout of the code—the infrastructure logic remains exactly the same.
resource "aws_instance" "web"{
ami="ami-0c55b159cbfafe1f0"
instance_type="t3.micro"
subnet_id=aws_subnet.main.id
tags={
Name="web-server"
Environment="production"
}
}
variable "region"{
type=string
default="us-east-1"
description="AWS Region"
}
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t3.micro"
subnet_id = aws_subnet.main.id
tags = {
Name = "web-server"
Environment = "production"
}
}
variable "region" {
type = string
default = "us-east-1"
description = "AWS Region"
}
The formatted version is significantly easier to read. Attributes are aligned, indentation is consistent, and nested blocks are clearly structured. This makes future updates simpler and reduces formatting-related comments during code reviews.
Using a Terraform Formatter provides much more than visual improvements. Consistently formatted configuration files help teams maintain high-quality Infrastructure as Code projects and reduce errors caused by poorly organized code.
A Terraform Formatter is useful throughout the infrastructure development lifecycle. Consider formatting your configuration in the following situations:
Whether you're deploying a single virtual machine or managing hundreds of cloud resources across multiple environments, consistent formatting makes Terraform configurations easier to maintain, review, and scale.
Our formatter works with virtually all Terraform configuration types, including:
Regardless of your cloud provider, formatting helps maintain a consistent coding style across your Infrastructure as Code projects.
Following a few simple best practices can help keep your Terraform configurations clean, consistent, and easy to maintain. While a formatter automatically handles spacing and indentation, combining it with good coding practices results in a more professional Infrastructure as Code (IaC) project.
type, default, description, and validation attributes in a consistent order.Although formatting is straightforward, developers occasionally encounter issues that prevent Terraform files from being formatted correctly. The following are some of the most common problems.
| Error | Description | Solution |
|---|---|---|
| Missing Curly Braces | Resource or module blocks are not properly closed. | Ensure every opening brace has a matching closing brace. |
| Invalid HCL Syntax | The configuration contains syntax errors. | Fix the syntax before formatting. |
| Incorrect Quotes | Strings are missing quotation marks. | Wrap string values inside double quotes where required. |
| Improper Indentation | Manual edits create inconsistent spacing. | Run the formatter to standardize indentation. |
| Mixed Tabs and Spaces | Different indentation styles are used throughout the file. | Use a consistent indentation style. |
| Duplicate Variable Names | Multiple variables share the same identifier. | Rename variables so each has a unique name. |
| Unclosed Blocks | Nested blocks are incomplete. | Verify the structure of all nested resources and modules. |
| Unsupported Characters | Hidden or copied characters cause parsing errors. | Remove invisible characters and paste plain text. |
variables.tf files when appropriate.outputs.tf for better maintainability.Unlike desktop formatting tools that require installing Terraform locally, our online Terraform Formatter works directly in your browser. Simply paste your HCL configuration, click Format Code, and receive neatly formatted output within seconds.
No account creation, downloads, or setup is required. Whether you're formatting a small resource definition or a large multi-module configuration, the tool provides a fast and reliable way to improve readability while preserving the behavior of your Terraform code.
Maintaining well-formatted Terraform code is an essential part of building reliable Infrastructure as Code projects. Clean formatting improves readability, simplifies collaboration, reduces unnecessary code review comments, and makes long-term maintenance significantly easier. Whether you're deploying infrastructure on AWS, Microsoft Azure, Google Cloud Platform, Kubernetes, or another supported provider, consistently formatted HCL files help your team work more efficiently.
Our free Terraform Formatter provides a quick and convenient way to organize your Terraform configuration directly in your browser. Simply paste your HCL code, click Format Code, and instantly receive clean, standardized output that's ready to copy into your project. No installation, registration, or complex setup is required.
For an even smoother Infrastructure as Code workflow, consider using this formatter together with our other developer tools such as the Terraform Variable Generator, Terraform Validator, JSON Formatter, YAML Formatter, and additional cloud utilities available on Calculator Apps.
terraform fmt command, making your configuration files clean, readable, and easier to maintain.