DevOps
Terraform Variable Cleanup: Remove Inputs Modules No Longer Read
Terraform variable cleanup starts when modules keep input variables that are ignored, hard-coded elsewhere, or left behind after infrastructure moved. Stale variables make modules harder to call, invite false confidence, and can hide the difference between what a caller sets and what infrastructure actually uses.
The useful output is a module interface change with caller evidence, plan review, documentation updates, and a migration note for any downstream stacks.
Key takeaways
- Check variable declarations, references, defaults, validation, docs, examples, and callers together.
- Treat public modules more carefully than private one-stack modules.
- Remove ignored variables after callers stop setting them, not before.
- Use plan review to confirm infrastructure behavior does not change unexpectedly.
- Prevent recurrence by marking temporary variables with removal conditions.
Variable Evidence
| Check | What to look for | Cleanup signal |
|---|---|---|
| References | Module code, locals, dynamic blocks, outputs | Variable is declared but unread |
| Callers | Environment overlays, wrapper modules, examples | No supported caller sets it |
| Defaults | Legacy compatibility, null behavior, validation | Default no longer changes behavior |
| Docs | README tables, upgrade guides, generated docs | Interface docs can shrink safely |
Do not rely only on text search if code generation or wrapper modules create calls.
Review Record
terraform_variable_review:
module: networking/vpc
variable: enable_legacy_nat
code_references: none
callers_setting_value: staging-old
proposed_change: remove caller setting, then delete variable next release
This staged approach avoids breaking callers that fail on unknown arguments.
Cleanup Path
First, stop setting the stale variable in callers you own. Then release a compatibility version if other teams consume the module. Update docs, examples, and tests. After supported callers migrate, remove the variable declaration, validation, and upgrade note. Review the plan for affected stacks before applying.
Do not rush variables in shared modules, registry-published modules, or modules used by customer environments. Do not rush variables that appear unused because they influence generated files or external tooling.
Prevention
Require module variables to include purpose, owner, default reason, and whether they are part of the public interface. Temporary inputs created for migrations should include the version or date when they can be removed.
FAQ
Can removing an unread variable still break Terraform?
Yes. Callers that still pass the variable may fail validation. Clean callers before deleting the interface.
Should compatibility variables stay forever?
No. Versioned modules and upgrade notes are better than permanent confusing inputs.