Infrastructure as Code

Modules and Reusable Infrastructure

Package related resources into reusable OpenTofu modules with intentional inputs, encapsulated internals, selected outputs, and controlled version boundaries.

Intermediate14 min read
Infrastructure as Code lessonDelivery and reliability foundationsLearn

Package related resources into reusable OpenTofu modules with intentional inputs, encapsulated internals, selected outputs, and controlled version boundaries.

What you will be able to do

  • Distinguish module package from module inputs in a realistic modules and reusable infrastructure case.
  • Interpret the delivery evidence and boundary associated with resource group.
  • Choose an appropriate action involving module outputs without exceeding the named operational scope.
  • Verify version boundary through an observable service result and reproducible handoff.

01

Frame Modules and Reusable Infrastructure

Package related resources into reusable OpenTofu modules with intentional inputs, encapsulated internals, selected outputs, and controlled version boundaries.

Three teams need the same service network pattern with different address ranges. Copying resource blocks has already produced inconsistent security settings.

Keep the delivery target, declared intent, execution evidence, reliability boundary, and recovery choice separate. Start with observable state and preserve enough context for another operator to reproduce the decision.

02

Module package

A module is a directory of configuration files that packages resources used together. Within modules and reusable infrastructure, this role answers a separate delivery or reliability question and keeps its own evidence.

Create one network module around the shared service pattern. Apply that action to the named service case before widening the rollout, infrastructure scope, or incident response.

Respect this boundary: do not place unrelated database ownership inside the network module. The observable result is specific: the module has one coherent infrastructure responsibility.

03

Module inputs

Module inputs expose the values callers are expected to choose. Within modules and reusable infrastructure, this role answers a separate delivery or reliability question and keeps its own evidence.

Accept the environment name and address range through typed variables. Apply that action to the named service case before widening the rollout, infrastructure scope, or incident response.

Respect this boundary: do not expose every internal resource argument as a public option. The observable result is specific: callers can vary required properties without editing internals.

04

Resource group

Module resources remain encapsulated and are addressed through the module instance. Within modules and reusable infrastructure, this role answers a separate delivery or reliability question and keeps its own evidence.

Keep the network and its required security boundary together. Apply that action to the named service case before widening the rollout, infrastructure scope, or incident response.

Respect this boundary: do not depend on callers reaching into private implementation details. The observable result is specific: each module instance creates one complete approved pattern.

05

Module outputs

Outputs selectively expose values that callers need from encapsulated resources. Within modules and reusable infrastructure, this role answers a separate delivery or reliability question and keeps its own evidence.

Publish the network identifier required by the service module. Apply that action to the named service case before widening the rollout, infrastructure scope, or incident response.

Respect this boundary: do not export sensitive or unstable implementation details. The observable result is specific: the caller receives one documented network identifier.

06

Version boundary

A module version boundary controls when callers adopt changes to reusable infrastructure behavior. Within modules and reusable infrastructure, this role answers a separate delivery or reliability question and keeps its own evidence.

Constrain the registry module version and review upgrades deliberately. Apply that action to the named service case before widening the rollout, infrastructure scope, or incident response.

Respect this boundary: do not consume an unconstrained moving module release in production. The observable result is specific: repeated initialization selects an approved compatible module version.

07

Apply Modules and Reusable Infrastructure to One Service Change

Use one bounded delivery decision: Three teams need the same service network pattern with different address ranges. Copying resource blocks has already produced inconsistent security settings.

First, create one network module around the shared service pattern. Then, accept the environment name and address range through typed variables. Keep both observations attached to the exact revision, environment, or service window.

Next, keep the network and its required security boundary together. After that, publish the network identifier required by the service module. Close the work only after you constrain the registry module version and review upgrades deliberately.

08

Recap Before Practice and Prove

Module package: A module is a directory of configuration files that packages resources used together. In this service case, create one network module around the shared service pattern. Preserve the boundary: do not place unrelated database ownership inside the network module.

Module inputs: Module inputs expose the values callers are expected to choose. In this service case, accept the environment name and address range through typed variables. Preserve the boundary: do not expose every internal resource argument as a public option.

Resource group: Module resources remain encapsulated and are addressed through the module instance. In this service case, keep the network and its required security boundary together. Preserve the boundary: do not depend on callers reaching into private implementation details.

Module outputs: Outputs selectively expose values that callers need from encapsulated resources. In this service case, publish the network identifier required by the service module. Preserve the boundary: do not export sensitive or unstable implementation details.

Version boundary: A module version boundary controls when callers adopt changes to reusable infrastructure behavior. In this service case, constrain the registry module version and review upgrades deliberately. Preserve the boundary: do not consume an unconstrained moving module release in production.

NEXT STEP

Turn reading into recall

Practice the concepts without a timer, with coaching and retry available after every answer.

Open guided practice