Terraform Variable Size Calculator
Calculate total variables, locals and outputs in a configuration and score its interface complexity.
Inputs
Count of declared `variable` blocks.
Count of `local` values computed within the configuration.
Count of declared `output` blocks.
Variables without a default value, which callers must always supply.
Total Variables + Locals + Outputs
70
Interface Complexity
Moderate
Complexity Score
100.0
Required Variable Share
28.6%
Step by step
Total vars: variables + locals + outputs
35 + 20 + 15
= 70
Complexity: required×3 + optional×1 + locals×1.5 + outputs×1
10×3 + 25×1 + 20×1.5 + 15×1
= 100.0
How it works
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
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.
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