Typorithm · medium

Modules

terraform-modulesterraformmodulesourceoutputs
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn Modules

0%

State & Modules

A module block instantiates a reusable bundle of resources: source addresses where it lives, inputs like cidr are passed in, and outputs are read back as module.vpc.vpc_id.

A module is a reusable package of resources you call by name. The module block here creates a VPC stack under the local label "vpc".

source tells Terraform where to fetch the module — a registry path like terraform-aws-modules/vpc/aws, a git URL, or a local path — and version pins a registry release.

Inputs (cidr) flow in like function arguments, and outputs flow back out: anywhere else in the config you read them as module.vpc.vpc_id, here wiring the VPC's id into an instance's subnet.

01

module "name" { ... } instantiates a reusable package.

02

source addresses the module; version pins a registry release.

03

Read outputs as module.<name>.<output>.

module "vpc" {
  source  = "terraform-aws-modules/vpc/aws"
  version = "5.0.0"
  cidr    = "10.0.0.0/16"
}

resource "aws_instance" "web" {
  subnet_id = module.vpc.vpc_id
}

Read the implementation

Connect each part of the code to the concept before you type.

1. Module call

A module block instantiates a reusable package of resources under the local name "vpc".

module "vpc" {

2. Source address

source addresses where the module comes from — here a Terraform Registry path namespace/name/provider.

source  = "terraform-aws-modules/vpc/aws"

3. Pinned version

version pins the module release so upgrades are deliberate, not accidental.

version = "5.0.0"

4. Module input

cidr is an input variable the module exposes; you pass values in just like function arguments.

cidr    = "10.0.0.0/16"

5. Consuming an output

module.<name>.<output> reads a value the module exports — here the created VPC's id.

module.vpc.vpc_id

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

Modules: Lesson & Practice · Typorithm | ApplyDjinn