glunty

Terraform .tfvars Formatter

Clean up a .tfvars file. Aligned equals, sorted keys, consistent spacing.

What this tool does

Cleans up a Terraform .tfvars file. Normalizes the spacing around =, optionally aligns equals signs in a column, optionally sorts top-level keys alphabetically, and preserves comments. The tool handles strings, numbers, booleans, lists, and inline maps. It does not run a full HCL parse, so deeply nested or unusual constructs may pass through with minimal change rather than being reformatted. Everything runs in your browser; no upload.

How to use it

Paste your .tfvars content. Toggle Align equals signs if you want all = in a column (common style; some teams prefer single-space). Toggle Sort top-level keys for alphabetical order; keep it off if your file's order is meaningful. Press Format. Example: region="us-east-1" on one line and instance_count=3 on the next become two lines with the equals signs aligned and consistent spacing.

Common use cases

  • Cleaning up a hand-edited .tfvars before committing to a code review.
  • Normalizing files exported from a templating tool that produces messy output.
  • Sorting an environment file to make diffs easier to read across PRs.
  • Collapsing inconsistent indentation across maps and lists.
  • Bringing a copy-pasted snippet from documentation into the project's house style.

Common pitfalls

  • This is not terraform fmt. The official formatter runs against full HCL syntax and does the canonical thing. This tool is a lightweight client-side helper for .tfvars specifically. For production code, run terraform fmt in your build.
  • Heredoc strings. Multi-line strings using <<EOT syntax pass through unchanged. The tool does not reformat their contents.
  • Comment placement. Comments on the same line as a value (trailing comments) are preserved. Comments above a value are kept above. Comments inside a map or list may shift if you sort keys; review the output.

Frequently asked questions

How is this different from terraform fmt?
terraform fmt runs against full HCL syntax (modules, resources, expressions, functions) and applies the canonical Terraform style. This tool is a lightweight client-side formatter for .tfvars files specifically: it normalizes spacing, optionally aligns equals signs, and optionally sorts top-level keys. For production code, run terraform fmt in CI; this tool is for quick cleanup before pushing.
Why might I want to align equals signs?
Aligned = columns make .tfvars files scannable: each value lines up vertically, so a missing or misspelled key stands out. Some teams prefer the strict-single-space style instead, which produces cleaner diffs when a key changes length. The tool supports both via the toggle.
Does sorting keys affect Terraform behavior?
No. Terraform reads .tfvars as an unordered map; the order of keys in the file does not matter. Sorting alphabetically can make code review easier (the same key always appears at the same line). If your file has a deliberate grouping (provider config, then resource sizes, then tags), keep sort off.
What about heredoc strings (<<EOT ... EOT)?
Multi-line heredoc strings pass through unchanged. The tool does not reformat their internal contents because any change would alter the string value. The opening line (name = <<EOT) is normalized for spacing; the body and closing line are left alone.
Why is .tfvars separate from .tf?
.tf files contain the Terraform configuration: providers, resources, modules, expressions. .tfvars files contain only variable values that fill in variable "name" {} declarations. Keeping values separate lets you commit the configuration to source control and supply environment-specific values (dev.tfvars, prod.tfvars) without code duplication.
Are comments preserved?
Yes. Both # and // comments are preserved. Comments above an assignment stay above it; trailing comments on the same line stay with the value. If you sort keys, leading comments move with their assignment so the association is preserved.

Embed this tool

Free for any use; attribution appreciated. Paste this on your site:

The embed runs the same tool that lives at this URL. No tracking; no ads inside the embed. Resize height as needed for your layout.

Cite this tool

For academic, journalistic, or technical references. Pick a format:

Citations use 2026 as the publication year. Access date is left as a fillable placeholder where the citation style expects one.

Embedded tool from glunty.com