0
0
Terraformcloud~10 mins

Module sources (local, registry, git) in Terraform - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Module sources (local, registry, git)
Start Terraform config
Identify module source type
Local
Load from local path
Use module in config
Terraform plan/apply
Terraform reads the module source type (local path, registry, or git), loads the module accordingly, then uses it in the configuration.
Execution Sample
Terraform
module "example" {
  source = "./modules/example"
}

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

module "app" {
  source = "git::https://github.com/org/repo.git"
}
This config uses three modules: one local, one from the registry, and one from a git repository.
Process Table
StepModule NameSource TypeActionResult
1examplelocalRead source './modules/example'Load module files from local path
2examplelocalCheck version '1.0'Version info noted (local modules usually no version enforcement)
3vpcregistryDownload 'terraform-aws-modules/vpc/aws' version '3.0.0'Module downloaded from Terraform Registry
4vpcregistryVerify version '3.0.0'Version confirmed and module ready
5appgitClone repo 'https://github.com/org/repo.git'Module cloned from git repository
6appgitUse default branch or refModule ready for use
7allallModules loadedTerraform plan/apply can proceed
8--End of module source loadingAll modules ready for configuration use
💡 All module sources loaded successfully, ready for Terraform plan and apply
Status Tracker
VariableStartAfter Step 1After Step 3After Step 5Final
module.example.sourceundefined./modules/example./modules/example./modules/example./modules/example
module.vpc.sourceundefinedundefinedterraform-aws-modules/vpc/awsterraform-aws-modules/vpc/awsterraform-aws-modules/vpc/aws
module.app.sourceundefinedundefinedundefinedgit::https://github.com/org/repo.gitgit::https://github.com/org/repo.git
Key Moments - 3 Insights
Why does the local module not enforce version like registry modules?
Local modules are loaded directly from your file system, so Terraform does not manage versions for them. See execution_table rows 1 and 2 where version is noted but not enforced.
How does Terraform know which branch or commit to use for a git module?
If no specific ref is given, Terraform uses the default branch of the git repo. This is shown in execution_table row 6.
What happens if a module source is invalid or unreachable?
Terraform will fail during the module loading step, stopping before plan/apply. This is not shown here because all sources load successfully.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what source type is used for the 'vpc' module at step 3?
Aregistry
Blocal
Cgit
Dunknown
💡 Hint
Check the 'Source Type' column at step 3 in the execution_table.
At which step does Terraform clone the git repository for the 'app' module?
AStep 2
BStep 4
CStep 5
DStep 7
💡 Hint
Look for the action mentioning 'Clone repo' in the execution_table.
If the local module path changes, which variable in variable_tracker would update?
Amodule.vpc.source
Bmodule.example.source
Cmodule.app.source
DNone
💡 Hint
Local module source is tracked under 'module.example.source' in variable_tracker.
Concept Snapshot
Terraform modules can come from three main sources:
- Local path: direct folder on your computer
- Registry: official Terraform module repository with versioning
- Git: remote git repository URL
Terraform loads modules based on source type before planning.
Local modules do not enforce versions; registry modules do.
Git modules clone the repo and use default or specified refs.
Full Transcript
This visual execution shows how Terraform handles module sources from local paths, the Terraform Registry, and git repositories. It starts by reading the module source type, then loads the module accordingly. Local modules load directly from the file system without strict version enforcement. Registry modules are downloaded with version checks. Git modules are cloned from remote repositories using the default branch or specified references. After all modules are loaded, Terraform proceeds to plan and apply. Variables track the source values for each module as they update through the steps. Key beginner questions about versioning and git refs are answered by referencing the execution steps. The quiz tests understanding of source types, steps of cloning, and variable tracking. The snapshot summarizes the core concepts for quick recall.