Terraform HCL Formatter & Validator
Paste your Terraform HCL code to format, validate, and beautify it instantly with syntax highlighting.
About This Tool
The Terraform HCL Formatter & Validator is a free browser-based tool that helps DevOps engineers and infrastructure developers format, validate, and beautify HashiCorp Configuration Language (HCL) code. HCL is the primary configuration language for Terraform, used to define cloud infrastructure resources across AWS, Azure, GCP, and dozens of other providers.
Proper formatting is critical in Terraform codebases for readability, code review efficiency, and maintaining consistency across teams. This tool supports both HCL1 and HCL2 syntax and provides configurable indentation (2 or 4 spaces), equals sign alignment within blocks, alphabetical attribute sorting, and real-time syntax highlighting with line numbers.
The formatter handles all standard Terraform constructs including
resource, data, variable, output, locals, module,
terraform, and provider blocks. Nested blocks, heredoc strings,
interpolation expressions, and complex expressions with functions are
all properly formatted. If you need to convert HCL to JSON or vice
versa, try the HCL to JSON Converter. For
formatting YAML configuration files used alongside Terraform, the
YAML Formatter is a great companion tool.
And for general JSON configuration, the
JSON Formatter can help.
All processing happens entirely in your browser. Your Terraform code never leaves your machine — no server round-trips, no logging, and no third-party access to your infrastructure definitions. This makes it safe for production configurations containing sensitive provider credentials, backend settings, and internal infrastructure details.
How to Use
- Paste your Terraform HCL code into the HCL Input panel on the left.
- Choose your preferred indentation (2 or 4 spaces) using the toggle buttons.
- Toggle Align = to align equals signs within blocks for cleaner visual layout.
- Toggle Sort Attrs to sort resource attributes alphabetically within each block.
- Click Minify to compress the code by removing comments and extra whitespace.
- Click Copy or press Ctrl+Shift+C to copy the formatted output to your clipboard.
- Click Sample to load example Terraform code and see the formatter in action.
Popular Terraform HCL Formatting Examples
FAQ
What HCL syntax versions are supported?
The tool supports both HCL1 (legacy) and HCL2 (current) syntax used by Terraform 0.12 and later. It handles all standard block types including resource, data, variable, output, locals, module, terraform, provider, moved, import, and check blocks.
Does it validate my Terraform code?
The tool performs structural validation including matching braces, brackets, and parentheses. It checks for unclosed blocks and mismatched delimiters. However, it does not validate Terraform-specific semantics like provider argument requirements or resource schema compliance — for that you need terraform validate.
How does equals sign alignment work?
When Align = is enabled, the formatter finds groups of consecutive assignment lines within the same block (e.g., cidr_block = ..., vpc_id = ...) and pads shorter keys with spaces so all equals signs line up vertically. This is the same behavior as terraform fmt.
What does the Sort Attrs option do?
Sort Attrs alphabetically reorders simple key = value assignments within each block. It does not reorder nested blocks, comments, or blank lines — only direct attribute assignments. This can help maintain a consistent ordering convention across your team's Terraform modules.
Is my data safe?
Yes. All formatting and validation runs entirely in your browser using JavaScript. No data is sent to any server. Your Terraform configurations, provider credentials, backend settings, and infrastructure details never leave your machine. You can verify this by checking the Network tab in your browser's developer tools.
How does syntax highlighting work?
The output panel uses color-coded syntax highlighting: purple for block types and keywords (resource, variable, etc.), cyan for type annotations (string, number, bool), green for strings and heredocs, blue for numbers, orange for booleans, red for null, yellow for function names, and gray for comments. Line numbers are displayed alongside the code.
Can I format Terragrunt HCL files?
Terragrunt uses the same HCL syntax as Terraform, so this formatter works for Terragrunt configuration files as well. The block types may differ (e.g., terraform, include, dependency), but the structural formatting and alignment features apply the same way.
Related Tools
HCL ↔ JSON Converter
Convert between Terraform HCL and JSON formats with syntax highlighting and tree view.
Terraform Variable Generator
Generate Terraform variable definitions (variables.tf) and tfvars files from a visual form with type support and validation rules.
YAML Formatter
Format, validate, and minify YAML with customizable indentation and syntax error display.
JSON Formatter
Format, validate, and beautify JSON with syntax highlighting and tree view.
SQL Formatter
Format, beautify, and minify SQL queries with dialect support for MySQL, PostgreSQL, and SQLite.