How to fix Error: No source for module in Terraform

TerraformINTERMEDIATEHIGHUpdated Dec 31, 2025· 119 views

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
}
  1. Verify the module block has a source argument
  2. Verify the source path is correct
  3. Run terraform init to download modules
  4. Validate the module name for registry modules
terraform — error
module "example" {
source = "./modules/example" # Local path
# or
source = "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

  1. The module block is missing the source argument entirely
  2. The source path is incorrect or has a typo (e.g., "./modules/example" vs "./module/example")
  3. Local module directory does not exist or is referenced with wrong relative path
  4. Registry module name is misspelled or uses invalid format (should be namespace/name/provider)
  5. terraform init has not been run after adding or modifying the module source
  6. Network connectivity issues preventing access to remote module sources
  7. Private repository modules lack proper authentication (SSH keys or credentials)

How to fix "Error: No source for module"

1Verify the module block has a source argument

Open your Terraform configuration file and check that your module block includes the source argument. The source argument is mandatory for all modules.

hcl
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.

2Verify the source path is correct

If using a local module source, ensure the path exists and is spelled correctly:

bash
# Check if local module directory exists
ls -la ./modules/example

Relative 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.

3Run terraform init to download modules

After verifying the source path, initialize Terraform to download the module:

bash
terraform init

This 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:

bash
terraform init -upgrade
4Validate the module name for registry modules

If using a module from the Terraform Registry, ensure the source format is correct. Registry modules require three or four slash-separated components:

hcl
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)

5Clear cache and reinitialize if issues persist

If the error persists after verifying the source path, clear Terraform caches and reinitialize:

bash
rm -rf .terraform .terraform.lock.hcl
terraform init

This 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.

6Check authentication for private modules

If using modules from private repositories (GitHub, GitLab, private registries), ensure proper authentication:

For GitHub SSH modules:

hcl
module "private" {
  source = "git@github.com:myorg/mymodule.git"
}

For Terraform Cloud private registry:

hcl
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.

Official resources & further reading