← Terraform: plan changes and operate infrastructure
04 / 6 · 40 MIN

Modules and identity

Reuse configuration without losing control of versions and addresses.

Concept and mechanism

A module organizes resources and an interface of inputs and outputs. Reuse does not automatically make a source trustworthy or remove change review. Define contracts, validations, and a version strategy for consumers. The lock file pins provider dependencies but does not pin remote module version selections in the same way. Use a version or reference appropriate to the source and review upgrades. Child-module resources remain integrated into the calling configuration. An address identifies an instance in state; reorganizing code may change that address even when the same remote object should remain. Review must separate address changes from physical infrastructure changes.

Guided application

In a fictional exercise, a count-managed environment list loses its first element and changes index-to-object correspondence. For stable identities, assess for_each with known, nonsensitive keys. Do not use a secret as a key because instance identity appears in output. A moved block records an address transition and helps preserve the existing binding; it does not migrate a database to another region or copy data. Inspect the refactoring plan and avoid accepting unexpected destruction as an inevitable cost of reorganizing code. Keep moved-block history while consumers may still upgrade from older versions. Removing that history can break the upgrade path for a team that has not yet caught up.

IN PRACTICE

Renaming module.rede to module.network needs identity mapping rather than only text replacement.

Common pitfalls

Lock file as every module version; sensitive key; moved as data migration.

Related topics: Configuration and dependencies · Plans and validation · State and collaboration

Take this idea with you

Keep contracts, versions, and addresses predictable for every consumer.

Create account

Reference: Root and reusable child modules · Terraform v1.16 concepts; official documentation consulted 2026-09-30; provider and backend capabilities must be confirmed