How to fix Error: No source for module in Terraform
The "No source for module" error occurs when Terraform cannot locate the module source you specified. This happens when the module path is missing, incorrect, or the modules have not been initialized. Resolving this requires verifying the source path and running terraform init.
Quick fix
Fixes Error: No source for module
module "example" {
source = "./modules/example" # Local path
# or
source = "hashicorp/consul/aws" # Registry module
}- Verify the module block has a source argument
- Verify the source path is correct
- Run terraform init to download modules
- Validate the module name for registry modules
module "example" {source = "./modules/example" # Local path# orsource = "hashicorp/consul/aws" # Registry module}Error: No source for module
What this error means
This error indicates that Terraform is unable to find the module source you specified in your module block. Every Terraform module requires a `source` argument that tells Terraform where to retrieve the module configuration files. The error can occur for local modules (relative or absolute file paths), remote modules from the Terraform Registry, or modules stored in Git repositories. Without a valid source, Terraform cannot download or access the module code needed for your configuration.
Typical symptoms
- Terraform init command fails with "No source for module" error
- Module blocks show errors during terraform plan or apply
- Error message indicates a specific module name that cannot be resolved
- terraform validate reports module source problems
Common causes
- The module block is missing the source argument entirely
- The source path is incorrect or has a typo (e.g., "./modules/example" vs "./module/example")
- Local module directory does not exist or is referenced with wrong relative path
- Registry module name is misspelled or uses invalid format (should be namespace/name/provider)
- terraform init has not been run after adding or modifying the module source
- Network connectivity issues preventing access to remote module sources
- Private repository modules lack proper authentication (SSH keys or credentials)
How to fix "Error: No source for module"
Open your Terraform configuration file and check that your module block includes the source argument. The source argument is mandatory for all modules.
module "example" {
source = "./modules/example" # Local path
# or
source = "hashicorp/consul/aws" # Registry module
}If the source argument is missing, add it with the correct module path or registry reference.
If using a local module source, ensure the path exists and is spelled correctly:
# Check if local module directory exists
ls -la ./modules/exampleRelative paths like ./modules/example are relative to the directory containing your Terraform configuration file, not your current working directory. Use terraform init from the correct directory.
After verifying the source path, initialize Terraform to download the module:
terraform initThis command downloads modules from the specified sources into the .terraform/modules directory. If the module source changed, you may need to use the -upgrade flag:
terraform init -upgradeIf using a module from the Terraform Registry, ensure the source format is correct. Registry modules require three or four slash-separated components:
module "vpc" {
source = "hashicorp/vpc/aws" # namespace/name/provider
version = "~> 3.0"
}Common mistakes include:
- Using single slashes instead of proper module syntax
- Misspelling the namespace, module name, or provider
- Using submodules without the // syntax (e.g., terraform-google-modules/vm/google//modules/mig)
If the error persists after verifying the source path, clear Terraform caches and reinitialize:
rm -rf .terraform .terraform.lock.hcl
terraform initThis removes cached module data and forces Terraform to re-download modules fresh. The .terraform.lock.hcl file contains version constraints; removing it causes Terraform to re-resolve module versions.
If using modules from private repositories (GitHub, GitLab, private registries), ensure proper authentication:
For GitHub SSH modules:
module "private" {
source = "git@github.com:myorg/mymodule.git"
}For Terraform Cloud private registry:
module "private" {
source = "app.terraform.io/myorg/mymodule/aws"
}Ensure SSH keys are configured or API tokens are available in your environment for authentication.
Advanced notes
For complex module setups, use terraform init -reconfigure to clear internal state and force reconfiguration. Enable debug logging with export TF_LOG=DEBUG to see detailed module resolution attempts. For modules using variables in paths, note that Terraform does not support dynamic variables in source arguments—the source must be known at parse time. When working with monorepos or complex directory structures, use absolute paths or ensure relative paths are calculated from the module directory, not your current working directory.
Frequently asked questions
- What does "Error: No source for module" mean?
- This error indicates that Terraform is unable to find the module source you specified in your module block. Every Terraform module requires a source argument that tells Terraform where to retrieve the module configuration files. The error can occur for local modules (relative or absolute file paths), remote modules from the Terraform Registry, or modules stored in Git repositories.
- How do I fix "Error: No source for module"?
- The "No source for module" error occurs when Terraform cannot locate the module source you specified. This happens when the module path is missing, incorrect, or the modules have not been initialized. Resolving this requires verifying the source path and running terraform init.
- What causes "Error: No source for module"?
- The module block is missing the source argument entirely The source path is incorrect or has a typo (e.g., "./modules/example" vs "./module/example") Local module directory does not exist or is referenced with wrong relative path
- Is the "Error: No source for module" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.