🎓 A1Learner
🔍
0 of 50 lessons completed

The Terraform Registry

The Terraform Registry is a public library of modules written by other people. It holds modules for common jobs, such as building a VPC, and each one is pinned to a version.

A Registry source address

The address names the module on the Registry. The version pins it to one release.

module "vpc" {
  source  = "terraform-aws-modules/vpc/aws"
  version = "5.19.0"
}

Download the module

Init downloads the module into the local .terraform folder. The version is recorded in the lock file.

terraform init

Never leave the version off

Without a version, init takes the latest release. A new release can change what the module builds.

module "vpc" {
  source = "terraform-aws-modules/vpc/aws"
  # No version: Terraform takes the latest.
  # Do not do this in real work.
}

Example

# Shown, not run. This module and version exist in the Registry.
module "vpc" {
  source  = "terraform-aws-modules/vpc/aws"
  version = "5.19.0"

  name = "example-vpc"
  cidr = "10.0.0.0/16"

  azs             = ["us-east-1a", "us-east-1b"]
  private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
  public_subnets  = ["10.0.101.0/24", "10.0.102.0/24"]
}

Key points

  • The Registry lists modules with their inputs, outputs, and examples.
  • A Registry module is called with a source address, not a folder path.
  • The source address names the author, the module, and the provider.
  • Pin the version so the module cannot change under you.
  • Read the module inputs before you use it.
  • A popular module with recent releases is a safer choice.

This is a community VPC module from the Terraform Registry, shown as configuration only and not applied. Its inputs match the lesson: a name, a CIDR block, and lists of subnets.

Note

The version in this lesson is 5.19.0, the release checked against the Registry.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

Why pin a Registry module to a version?