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.
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.
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 = "[email protected]: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.
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.
Error: Error installing helm release: cannot re-use a name that is still in use
How to fix "release name in use" error in Terraform with Helm
Error: Error creating GKE Cluster: BadRequest
BadRequest error creating GKE cluster in Terraform
Error: External program failed to produce valid JSON
External program failed to produce valid JSON
Error: Unsupported argument in child module call
How to fix "Unsupported argument in child module call" in Terraform
Error: network is unreachable
How to fix "network is unreachable" in Terraform