All Tools View Categories About Contact Privacy

Terraform Locals Generator

Build a valid Terraform locals block (HCL) with typed local values.

Runs entirely in your browser - nothing is uploaded and no cloud connection is made.
0
local values
Your generated locals block will appear here.

About Terraform Locals Generator

A locals block is the Terraform mechanism for naming a value once and reusing it everywhere, which keeps a configuration DRY and easy to read. The Terraform Locals Generator builds that block from a small form, so you can produce correctly quoted HCL without hand-writing attribute lines or worrying about string versus expression quoting. It is the quickest path from a list of values in your head to a paste-ready locals { } block.

Each local can be a string, number, bool or a raw HCL expression such as a resource reference. The generator validates the block as a whole: empty keys and duplicate keys are both reported, because a single locals block cannot contain two locals with the same name. Everything is assembled in your browser, so nothing is uploaded and no provider or cloud account is contacted. Use it to scaffold the locals for a new module, to normalise values copied from several sources, or to demonstrate the locals pattern in a workshop.

Because the output is ordinary HCL, it validates with terraform validate and slots into any module. The live local count and duplicate checks make it a gentle teaching tool: newcomers see immediately why a name must be unique and why an empty key is rejected, which prevents the most common locals mistakes before they reach a plan.

The generator also pairs naturally with code review: a reviewer can regenerate the locals from the form to confirm the intended types, which catches a string that should have been a number or a raw reference that was mistakenly quoted. Small type mistakes like those are easy to miss by eye but obvious once the block is rendered in canonical form.

Features

  • Typed values - string, number, bool and raw HCL expressions.
  • Multiple values - add or remove as many locals as you like.
  • Duplicate detection - repeated names are flagged before output.
  • Empty-key detection - a missing key is reported per row.
  • Live count - a stat shows how many locals are in the block.
  • Type-safe preview - see at a glance whether a value became a quoted string or a bare literal.
  • Copy / Download / Print - export locals.tf wherever you need it.
  • Copy as Markdown - a fenced block for docs and pull requests.
  • Word-wrap toggle - keep long raw expressions readable.
  • Example presets - realistic samples one click away.
  • Review friendly - regenerate to confirm intended types during review.
  • Private - assembled in your browser, nothing leaves the page.

How to Use

  1. Click + Add local to add a row for each value.
  2. Type a name and choose its type from the dropdown.
  3. Enter the value - a literal for string, number or bool, or a reference for raw.
  4. Add more rows as needed, avoiding duplicate names.
  5. Click Generate HCL to build the locals block.
  6. Review the count and any errors on the right.
  7. Fix duplicates or empty keys and regenerate if needed.
  8. Toggle word wrap if a raw expression is long.
  9. Use Copy Markdown to drop the block into a review comment.
  10. Export by copying, copying Markdown, downloading locals.tf or printing.
  11. Load a sample or clear to reset the form.

Examples

Example. Enter four locals: name as the string web, port as the number 8080, enabled as the bool true, and id as the raw expression aws_instance.web.id. The generator emits a single locals { } block where name is quoted, port and enabled are unquoted literals, and id passes through verbatim as a reference. The count reads four. If you then add a second local also named name, the tool reports a duplicate and refuses to emit until the clash is resolved.

The same four-value example also shows typing discipline: because port is a number, the emitted line is port = 8080 with no quotes, whereas name becomes name = "web". Mixing those up is a common source of plan drift, and the preview makes the distinction unmistakable.

Benefits

  • Correct schema - a valid locals block every time.
  • Typed - correct HCL literals for every type.
  • Type-safe - literals and references are emitted in the correct HCL form.
  • Validated - duplicate and empty keys are caught early.
  • Fast - scaffold locals without a terminal.
  • Reusable - DRY values across the configuration.
  • Reviewable - canonical output surfaces type mistakes early.
  • Private - everything runs in the browser.

Frequently Asked Questions

What is a locals block?
A locals block defines named expressions that you can reuse throughout a Terraform configuration, keeping repeated values DRY.
Which value types are supported?
Each local value can be a string, number, bool, or a raw HCL expression (such as a reference like aws_instance.web.id).
Are duplicate keys allowed?
No. Duplicate local names are flagged as errors because they are not valid in a single locals block.
Does this connect to a cloud?
No. Everything is assembled in your browser and nothing is uploaded.
Can I download it?
Yes. Copy the HCL, download locals.tf, or print it.