DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk4 min

Terraform Module Inputs, Outputs, and Sources: How Modules Pass Data

Terraform modules pass values through declared inputs and outputs. Learn how callers connect modules, what source means, and when remote state is a separate concern.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Terraform modules pass data through explicit inputs and outputs: a caller supplies named arguments to a child module, and the child exposes selected values for the caller to use. The caller can wire one module’s output into another module’s input. A module’s source is different: it identifies where Terraform gets the module’s code, not a value passed at runtime.

How data moves between Terraform modules

Think of a module call as a boundary with two directions:

As an Amazon Associate I earn from qualifying purchases.

  • Into the child: the caller sets arguments in a module block. The child declares matching input variables.
  • Back to the caller: the child declares output values. The caller references an output as module.<label>.<output>.

The module label is the local name assigned in the caller’s configuration. It is not necessarily the module’s registry name. Only values declared as outputs are exposed; a child’s internal resource attributes are not automatically available to its caller. See HashiCorp’s module block reference and output documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Inputs: values the caller supplies

A child module declares each input with a variable block. The caller supplies a value using the same variable name as an argument in the module block. The child can then use that variable in resources, data sources, or expressions.

variable "base_cidr_block" {
  type = string
}

module "network" {
  source = "./modules/network"

  base_cidr_block = "10.0.0.0/8"
}

Here, the child module must declare base_cidr_block; the caller provides its value. If a variable has no default, the caller must supply it before Terraform can generate a plan. A default makes the input optional. Declaring a type and, where useful, validation rules helps make the module’s input contract clearer. See Terraform input variables.

Outputs: values the child exposes

A child module uses an output block to make a selected value available to its caller. For example, a network module might expose subnet IDs, which the caller can pass to an application module.

module "network" {
  source = "./modules/network"

  base_cidr_block = "10.0.0.0/8"
}

module "app" {
  source = "./modules/app"

  subnet_ids = module.network.subnet_ids
}

For this connection to work, the network module must declare an output named subnet_ids, and the app module must declare an input variable with that name. In module.network.subnet_ids, network is the caller’s module-block label and subnet_ids is the child’s output name. The same reference pattern can supply a resource argument instead of another module input.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Outputs are an intentional interface, not an automatic export of every value inside a module. A module author chooses which values to expose. Common examples include resource IDs, names, and endpoints needed by downstream configuration. See output values.

Sources: where Terraform gets module code

The source argument selects the module’s configuration location. It does not pass runtime data to the child. Supported source types include local directories, registry modules, and version-control repositories. A local source might be ./modules/network; a registry source can use a version constraint, while a Git source can use ref to select a branch, tag, or commit.

The version argument applies to registry modules. A local module uses the code in the local source tree, so its versioning is managed with that repository rather than a registry version constraint. Terraform must know the source during initialization. Current module syntax also permits source expressions using constant input variables and local values; a variable used in source must declare const = true. This does not make arbitrary runtime expressions suitable for selecting module code.

After changing a module source or a registry module version, run terraform init so Terraform can install or update the module code. For an already-installed module, terraform init -upgrade updates modules to the newest versions permitted by their configured constraints. Consult the module block syntax and init command reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How Terraform orders connected modules

When one module argument refers to an upstream module output, that reference expresses the relationship between them. Terraform can infer the dependency and order operations accordingly. The same principle applies when a resource argument refers to a module output.

Use depends_on for a dependency that matters but is not represented by an argument or other reference. It is not a substitute for passing a value: use an output-to-input reference when the downstream module actually needs data from the upstream one. See the module block reference.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why a flatter module composition is often easier to manage

For modules that belong to the same configuration, a common pattern is to place related modules under one parent and connect them there. The parent can pass outputs from one child into another child’s inputs, making the wiring visible in one place.

HashiCorp describes this approach as “module composition”: combining composable building blocks to produce a larger system. Its guidance generally favors a relatively flat module tree; excessive nesting can make modules harder to reuse and the configuration harder to understand. Nest a module when it is a meaningful part of another module’s implementation, rather than simply to relay values through several layers. See module composition and module development guidance.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Sharing values between separate Terraform configurations

Direct references such as module.network.subnet_ids work within the calling module hierarchy. A separate Terraform configuration does not use that child-module reference to reach into another configuration. One configuration can instead read root outputs from another configuration’s state with terraform_remote_state. That is cross-configuration state access, not ordinary input-and-output wiring between child modules. See remote state data and output values.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.