Terraform HCL Formatter

Format and sort HCL code — indent blocks, align equals, reorder resources, variables, and modules

  1. Home
  2. /
  3. Terraform HCL Formatter

Formatted Output

Paste HCL and click Format & Sort

Blocks

0

Sorted

-

Changed

-

Lines

0

What Is HCL Sorting and Formatting?

The Terraform HCL Formatter goes beyond basic formatting by also sorting blocks alphabetically within your configuration. Well-organized Terraform code follows consistent conventions: resources are grouped and sorted, variables are listed alphabetically, and modules are organized in a predictable order. This tool applies two key transformations: formatting (indentation, alignment, whitespace) and sorting (block ordering for resources, variables, outputs, and modules). It helps teams maintain consistent code organization across projects, makes pull requests easier to review, and reduces merge conflicts. When enabled, the sort feature reorders blocks while preserving their internal structure, ensuring your configuration follows a logical, predictable arrangement.

How to Use This Tool

  1. Paste your HCL code — Enter or paste Terraform HCL configuration into the input area.
  2. Toggle options — Enable or disable Sort blocks and Align equals checkboxes as needed.
  3. Click Format & Sort — The tool applies formatting and optionally reorders blocks alphabetically.
  4. Review changes — The output panel shows the formatted code with a summary of sorted blocks and changes made.
  5. Copy the result — Click Copy to copy the formatted and sorted HCL to your clipboard.

Frequently Asked Questions

Is my data sent to a server?

No. All processing is performed locally in your browser. Your HCL data never leaves your device.

What is the difference between this and the Terraform Formatter tool?

This tool adds block sorting, while the basic Terraform Formatter only handles formatting. Use this tool when you need to reorganize your configuration files.

How does block sorting work?

Blocks are sorted alphabetically by type first (data sources, locals, modules, outputs, providers, resources, variables), then by name within each type.

Can I disable sorting and only format?

Yes. Uncheck the Sort blocks option to apply formatting without changing block order.

Is this tool free to use?

Yes. This tool is completely free with no usage limits or registration required.

Last updated: 9 Jul 2026