← Terraform Associate: infrastructure as code
05 / 8 · 20 MIN

Modules and usage contracts

Reuse infrastructure through explicit inputs, outputs, and versions.

Concept and mechanism

A module groups configuration behind an interface. The root passes values to variables declared by the child module; matching names do not create automatic inheritance. Published outputs let the caller consume results without knowing the entire implementation. source identifies where to obtain the module. For registry sources, version constrains versions; Git sources use their own reference mechanisms. The provider lock does not pin remote module versions. Reuse reduces repetition but can also spread an incorrect change across many consumers if updates are uncontrolled.

Guided application

When creating an application-environment module, expose decisions consumers need to make: sizing, classification, and integration destinations, for example. Document defaults and outputs. During an upgrade, compare old and new interfaces and review a representative consumer’s plan. A seemingly small version change may alter defaults and cause replacements. Retain a recoverable reference to the previous version while recognizing that returning to old code does not guarantee reversing data effects.

IN PRACTICE

A shared module changes default retention. Each consumer should assess the change instead of receiving it through an unreviewed update.

Common pitfalls

Assuming variable inheritance; depending on internals; updating references without reviewing plans.

Related topics: State, locking, and drift · Import, inspection, and diagnosis

Take this idea with you

A good interface enables reuse without hiding operating impact.

Create account

Reference: Module reference · 004