IAC / A CONCEPT NOTE

Terraform Modules

reusable, versioned infrastructure components

~70 sec read

Overview · mechanism
pitfall · examples

01 / THE SHORT VERSION

The idea in a few sentences.

A module is any directory with .tf files that exposes input variables and output values. You call a module with module "vpc" { source = "./modules/vpc", version = "1.2.0" }. Root modules are your main config; child modules encapsulate reusable patterns like networking, compute, or databases.

02 / FOLLOW THE MECHANISM

How a module works

  1. Terraform

    resolves the module source — a local path, Git URL, or Terraform Registry reference.

  2. Terraform

    evaluates the module block's input variables and passes them to the module's scope.

  3. Terraform

    merges the module's resources into the root graph — they're planned and applied alongside root resources.

  4. Root config

    references module outputs via module.vpc.vpc_id for use elsewhere in the stack.

04 / COMMAND NOTES

Read the command, then the result.

Inspect the flags and arguments before trying an example. Snippets can need local setup, replacement values, or resources in your own environment.

EXAMPLE 01 · REFERENCE

downloads module sources and providers

terraform init

EXAMPLE 02 · REFERENCE

inspect all provider versions in the module tree

terraform providers

Explore command anatomy in the CLI lab