All Tools View Categories About Contact Privacy

Terraform Workspace File Generator

Build a workspace-aware Terraform file (HCL) using terraform.workspace.

Runs entirely in your browser - nothing is uploaded and no cloud connection is made.
0
workspaces
Your generated workspace file will appear here.

About Terraform Workspace File Generator

Terraform workspaces let one configuration manage multiple state files, which is a common way to keep dev, staging and prod separate without copying code. The Terraform Workspace File Generator writes a locals block that maps each workspace to environment-specific configuration using the built-in terraform.workspace value. Add one workspace entry per row with its name, region and environment label, and the tool produces a lookup map plus a current local that resolves the active workspace.

This pattern means you write your resources once and let the chosen workspace decide the region and environment at apply time. Everything runs locally in your browser and nothing is uploaded, so your environment names stay private while you experiment. The generated HCL is valid, formatted and ready to paste into a main.tf without extra editing.

Because the mapping lives in a locals block, it is easy to read and to extend: add a new workspace row, regenerate, and the lookup grows without touching the rest of your module. This keeps environment differences explicit and reviewable instead of scattered across conditional expressions that are hard to test. It also makes onboarding faster because a new engineer can read the mapping in a single place and understand every environment the project supports.

Features

  • Workspace map - a map keyed by terraform.workspace holds each environment settings in one place.
  • Per-workspace config - capture region and environment label for every workspace you support.
  • current local - a lookup resolves the active workspace configuration automatically at plan and apply time.
  • Live stats - a stat badge shows how many workspaces were emitted, so you can confirm none were dropped.
  • Copy as Markdown - copy the HCL inside a fenced block for documentation and tickets.
  • Validation - missing name, region or environment are flagged before any output is produced.
  • Copy / Download / Print - get main.tf wherever you need it, including a printable view.
  • Sample loader - load dev/staging/prod rows to see a realistic result instantly.
  • Clear - reset the form to start a fresh mapping in one click.
  • Local first - no network calls, so the tool works offline and behind locked-down proxies.

How to Use

  1. Add workspaces - click "Add workspace" for each environment you want to support.
  2. Fill each row - type the workspace name, its region and its environment label (for example dev / us-east-1 / development).
  3. Generate - press "Generate HCL" to validate the rows and build the locals block.
  4. Review the stats - confirm the workspace count shown in the stats row matches what you entered.
  5. Export - Copy the HCL, Copy as Markdown for documentation, Download main.tf, or Print it.
  6. Wire your code - reference local.current.region and local.current.environment in your resources so they adapt per workspace.
  7. Re-run on change - add or rename a workspace and regenerate so the map stays accurate.
  8. Load a sample - when unsure, click Load sample to see a working example, then adapt it to your own names.

Examples

Example 1 - three environments. dev, staging and prod rows produce a map with three keys, each carrying its own region and environment.

Example 2 - two regions. a dev row in us-east-1 and a prod row in eu-west-1 show how region differences are captured per workspace.

Example 3 - current lookup. selecting the prod workspace makes local.current resolve to prod region and environment, so resources are created in the right place.

Example 4 - missing field. a row without a region is flagged, reminding you that every workspace needs complete configuration.

Example 5 - referencing. in a resource you can use local.current.region as the region argument, so the same code deploys to the right location per workspace.

Benefits

  • Correct schema - valid workspace-aware locals that terraform accepts without modification.
  • Clear - explicit per-workspace configuration is easy to review and audit.
  • Extensible - adding a workspace is a single new row rather than a new conditional.
  • Private - everything runs in the browser with no upload and no telemetry.
  • Portable - copy, copy-as-markdown, download or print the file wherever it is needed.
  • Consistent - one generated block keeps the pattern uniform across modules.
  • Fewer conditionals - a lookup map replaces scattered if/else expressions that are easy to get wrong.
  • Offline ready - with no network dependency the generator works in air-gapped environments.
  • Onboarding - a single mapping shows every environment, helping new engineers get oriented quickly.

Frequently Asked Questions

What does this tool generate?
It writes a locals block that maps each Terraform workspace to environment configuration (environment name and region) using terraform.workspace.
Why use terraform.workspace?
It returns the name of the currently selected workspace, letting one configuration behave differently per workspace.
How are workspaces added?
Add one row per workspace with its name, region and environment label.
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 main.tf, or print it.