Error: Unreadable module directory: "lstat modules/X: no such file or directory"
Fixes Terraform's "Error: Unreadable module directory ... lstat modules/X: no such file or directory" when a local module source path is wrong. Use when init fails on a local module. Fix the source path (relative to the calling file, with ./ prefix); not for registry download failures.
TL;DR
Your module block's local source path does not exist. Local sources are relative to the file that declares them and must start with ./ or ../. Fix the path, re-run terraform init.
The error
Error: Unreadable module directory
Unable to evaluate directory symlink: lstat modules/greetings: no such
file or directorySteps to fix
- Open the
moduleblock and read thesourcevalue.
- Expected: you see the path Terraform tried.
- Check it from the declaring file's directory:
ls [source]. Remember it is relative to the file, not to where you ran the command.
- Expected: you confirm the folder is missing or misspelled.
- Fix the path, keeping the
./prefix for local modules:
module "greeting" {
source = "./modules/greeting"
}- Expected: the path resolves from the declaring file.
- Run
terraform init.
- Expected: module installs; init succeeds.
When to use this
terraform initfails withUnreadable module directoryright after adding or moving a local module, especially after refactors that move folders.
When NOT to use this
Module not installedmeans init was never re-run. Registry/GitHub source failures are download problems, not path problems. Without the./prefix, Terraform treats the string as a Registry address and fails with a 404 instead.
Compatibility
- All Terraform versions; local module source resolution is unchanged.
Root cause
Local module sources are filesystem paths resolved at init time, relative to the configuration file containing the module block. A typo, a moved folder, or a missing ./ prefix (which flips interpretation to a Registry address) all produce this at init.
Edge cases
- Symlinked module dirs: a broken symlink gives the same
lstaterror; fix the link target. - Windows paths: use forward slashes; backslashes are not valid in source addresses.
- Monorepos: double-check which file declares the module; the relative base is that file's directory, not the repo root.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.