Module Source
The source argument in a Terraform module block tells Terraform where to download the module code from. It can be a local path, a registry address, a Git URL, or a private registry.
What Is a Module Source?
source is the only required argument in a module block, and the format decides how you pin versions.
HCL
module "local" { source = "./modules/vpc"} module "registry" { source = "terraform-aws-modules/vpc/aws" version = "~> 5.0"} module "git" { source = "git::https://github.com/atlassian-platform/tf-modules.git//networking/vpc?ref=v3.1.0"}| Source type | Version pinning |
|---|---|
| Local path | None |
| Registry | version argument |
| Git | ?ref= tag or commit |
The double slash selects a subdirectory inside the repository.
Common MistakePointing
ref=atmain. A breaking merge gets pulled in on the nextterraform init -upgrade. Pin a tag or commit.
Frequently Asked Questions
Why does version only work for some sources?
Only registries publish numbered releases. Git pins through ref in the URL, and local paths have no versioning.
What does the double slash in a source mean?
It separates the repository address from a subdirectory, so repo.git//networking/vpc uses the networking/vpc folder as the module root.
Found a mistake, an outdated step or a broken link?