Terraform tfvars Generator
Parse variables.tf declarations and scaffold clean terraform.tfvars or JSON files with comments and default values.
| Variable Name | Type | Status | Assigned Value |
|---|---|---|---|
| environment | string | Optional | |
| cluster_size | number | Optional | |
| enable_waf | bool | Optional | |
| subnet_ids | list | Required | |
| resource_tags | map | Optional |
# Target deployment environment (dev, staging, prod)
environment = "production"
# Desired number of worker nodes in the EKS cluster
cluster_size = 5
# Attach AWS WAF regional web ACL to ALB
enable_waf = true
# List of private subnet IDs for database tier
subnet_ids = ["subnet-1", "subnet-2"]
# Common cost allocation tags
resource_tags = {Do it offline:$
How to use it
- Paste your existing Terraform variables.tf declarations or use the default cloud infrastructure sample.
- Click 'Parse Variables' to extract variable names, data types (string, number, bool, list, map, object), and defaults.
- Inspect required variables (those without a default value) versus optional variables.
- Populate or override environment-specific values directly in the editable matrix.
- Choose between native HCL format (.tfvars) and machine-readable JSON format (.tfvars.json).
- Copy the generated file into your root module or environment-specific deployment repository.
Scaffold clean terraform.tfvars and terraform.tfvars.json variable files directly from HCL variables.tf declarations. Automatically parse types, default fallbacks, and descriptions into commented configuration files for multi-environment deployments.
How it works
Terraform automatically loads variable value definitions from any files named exactly 'terraform.tfvars' or ending with '.auto.tfvars'.
When variables are defined without default values in variables.tf, Terraform prompts interactively on the command line unless values are supplied via .tfvars, environment variables (TF_VAR_*), or CLI flags (-var).
Generating .tfvars files with embedded comments preserves context and architectural guidelines for operators executing applies in CI/CD pipelines.
The JSON format (terraform.tfvars.json) is commonly used when generating dynamic Terraform inputs from orchestration tools like Python, GitHub Actions, or HashiCorp Vault.
Examples
Every example on this page is executed against the same engine that powers the tool, on every build.
Gotchas worth knowing
Common errors
FAQ
What is the variable definition precedence in Terraform?
Terraform evaluates variable sources in order of increasing precedence (later sources override earlier ones): 1. Environment variables ('TF_VAR_<name>'), 2. 'terraform.tfvars' file, 3. 'terraform.tfvars.json' file, 4. Any '*.auto.tfvars' or '*.auto.tfvars.json' files sorted alphabetically, and 5. '-var' and '-var-file' options on the command line.
Should terraform.tfvars be committed to version control?
Generally no, if it contains sensitive values (such as database credentials or API secrets). Teams often commit a template file named 'terraform.tfvars.example' containing placeholders and comments, and add 'terraform.tfvars' to '.gitignore'. For non-sensitive configurations, committing environment-specific files like 'prod.tfvars' is standard practice.
When should I use terraform.tfvars.json instead of .tfvars?
Use 'terraform.tfvars.json' when your Terraform inputs are produced by programmatic pipelines or automated scripts (such as Python, Node.js, jq, or CI/CD runners). Terraform natively parses JSON files ending in '.tfvars.json', eliminating the need to construct HCL formatting programmatically.