Module Sources and the Terraform Registry
Every Terraform configuration is made of modules, and the source argument tells Terraform where each child module comes from. This lesson covers root and child modules and every kind of module source.
Learning outcomes
After completing this lesson, you will be able to:
- Distinguish root and child modules.
- Identify local, registry, Git and other module sources.
- Interpret Git references and subdirectory syntax in module sources.
Root and child modules
A module is a set of .tf files in one directory. The directory where you run Terraform is the root module. It can call other modules with module blocks; those are child modules, and they can call modules in turn. A module groups related resources behind an interface of input variables and outputs, so a caller can create a whole pattern, such as a network or a static website, with a few arguments.
module "network" {
source = "./modules/network"
cidr = "10.0.0.0/16"
}Modules installed by Terraform are stored in .terraform/modules, and terraform init (or terraform get, which only installs modules) downloads them. A module's code runs with the caller's credentials, so treat third-party modules like any other dependency: review them, prefer verified publishers and pin versions.
Local paths and registries
The source argument is required and, in Terraform 1.12, must be a literal string. The two most common forms are local paths and registry addresses.
- Local path: begins with
./or../, such as"./modules/network". The files are used in place, not copied, so edits take effect at once, and theversionargument is not allowed. - Public Terraform Registry:
NAMESPACE/NAME/PROVIDER, such as"terraform-aws-modules/vpc/aws". Supportsversion. - Private registry:
HOSTNAME/NAMESPACE/NAME/PROVIDER, such as"app.terraform.io/example-org/vpc/aws"for an HCP Terraform private registry. Supportsversionand needs credentials, for example fromterraform login.
The public registry marks some modules as partner modules, published by HashiCorp technology partners, and every module page lists its inputs, outputs, dependencies and versions.
The leading ./ matters
A path without ./, such as "modules/network", is not treated as a local path. Terraform interprets it as a registry address and fails.
Name the module source
Version control and other sources
Modules can also be installed from version control systems and from archives. The following table lists the forms.
| Source type | Example |
|---|---|
| GitHub shorthand | github.com/acme/terraform-aws-network |
| Bitbucket shorthand | bitbucket.org/acme/terraform-aws-network |
| Generic Git over HTTPS or SSH | git::https://git.example.com/network.git or git::ssh://[email protected]/network.git |
| Mercurial | hg::https://hg.example.com/network |
| HTTP archive | https://example.com/network-module.zip |
| Amazon S3 bucket | s3::https://s3-eu-west-1.amazonaws.com/acme-modules/network.zip |
| Google Cloud Storage | gcs::https://www.googleapis.com/storage/v1/acme-modules/network.zip |
For Git sources, append ?ref= to select a tag, branch or commit, as in git::https://git.example.com/network.git?ref=v1.4.0. A double slash selects a subdirectory of the repository: git::https://git.example.com/infra.git//modules/vpc?ref=v1.4.0. Git uses the credentials of the machine running Terraform, such as an SSH key.
The following diagram breaks a Git module source address into its parts.

Git module addresses
Choosing a source
A platform team keeps its modules in a private Git repository, one module per subdirectory, and tags releases such as network-v2.3.0. An application team wants version 2.3.0 of the network module. Which source should they use, and can they add version = "2.3.0"?
The decisive fact is the source type.
The source is git::ssh://[email protected]/platform/modules.git//network?ref=network-v2.3.0: the double slash selects the subdirectory and ref selects the tag. The version argument is not valid for Git sources. If the platform team published to an HCP Terraform private registry instead, callers could use a registry address with version constraints.
How do you select tag v2.0.0 of a module in a Git repository?
Show answer
Add ?ref=v2.0.0 to the source address; the version argument works only for registry modules.
Exam Tips
Remember for the exam
- The root module is the working directory; called modules are child modules.
- Local paths start with ./ or ../; registry addresses are NAMESPACE/NAME/PROVIDER.
- Git: ?ref= for revisions, // for subdirectories.
- In Terraform 1.12, source must be a literal string.