Terraform Variable Size Calculator
Measure the size and complexity of variable definitions across a Terraform configuration.
About Terraform Variable Size Calculator
Formula: total_vars = variables + locals + outputs. The complexity score weights required (no-default) variables highest since they represent mandatory caller burden, followed by local values (internal derived logic that's harder to trace), then optional variables and outputs. A module with many required variables and heavy local computation is harder to consume and maintain than one with sensible defaults and a thin interface.
Formula
complexity_score = required_vars × 3 + optional_vars × 1 + locals × 1.5 + outputs × 1
- required_vars
- Variables without a default (must be supplied by caller)
- optional_vars
- Variables with defaults
- locals
- Local computed values
- outputs
- Declared output blocks
Worked example
With the default values below, Terraform Variable Size Calculator returns Total Variables + Locals + Outputs of 70. Change any input above and every figure here is recalculated in your browser.
Inputs used
- Input Variablesaccepts 0–1,000,000 variables
- 35 variables
- Local Valuesaccepts 0–1,000,000 locals
- 20 locals
- Outputsaccepts 0–1,000,000 outputs
- 15 outputs
- Required (No Default) Variablesaccepts 0–1,000,000 variables
- 10 variables
Results
- Total Variables + Locals + Outputs
- 70
- Interface Complexity
- Moderate
- Complexity Score
- 100.0
- Required Variable Share
- 28.6%
Step by step
- 1Total vars: variables + locals + outputs= 70
- 2Complexity: required×3 + optional×1 + locals×1.5 + outputs×1= 100.0
Assumptions and limits
- The result is derived only from the 4 inputs listed above. Anything not among them is not part of the calculation.
- In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
- Figures are rounded for display to 1 decimal place, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.
How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.
Frequently Asked Questions
Why do required variables weigh more than locals?
Every required variable is something every caller of the module must understand and supply correctly — it's an ongoing tax on every consumer, whereas complex locals are a one-time authoring cost paid by the module maintainer.
What's a healthy number of required variables for a module?
Well-designed reusable modules often keep required variables under 5-8, pushing everything else to sensible defaults — a module needing 20+ required inputs is a signal it may be doing too much and could be split.
How do I count these in an existing configuration?
Use `grep -c` for `^variable`, `^locals` blocks (note locals blocks can contain multiple values), and `^output` across your `.tf` files, or `terraform-docs` which generates this inventory automatically.
Does a high output count indicate a problem?
Not inherently — modules meant to be composed by other modules often need many outputs to expose resource attributes; it's more of a complexity signal when combined with high required-variable counts on the same module.
Related Calculators
- Terraform Module Dependency Calculator
- Terraform Plan Complexity Calculator
- Terraform Resource Count Calculator
- Terraform State Size Calculator
- Terraform Apply Time Calculator
- Terraform Backend Storage Calculator
- Terraform Cloud Cost Calculator
- Terraform Drift Calculator
- Terraform Graph Complexity Calculator
- Terraform Infrastructure Score Calculator
You might also need
- Terraform Plan Complexity CalculatorCommonly used together
- Terraform Resource Count CalculatorCommonly used together
- Terraform Module Dependency CalculatorCommonly used together
- Terraform Graph Complexity CalculatorAlso in Terraform
- Terraform Drift CalculatorAlso in Terraform
- Terraform Workspace CalculatorAlso in Terraform
