Updated on 6/4/22 to include possible solutions 2 through 4.
Problem scenario
You are running a terraform command, but you receive this error:
Initializing modules…
- website_contint_bucket in
Error: Unreadable module directory
Unable to evaluate directory symlink: lstat foobar: no such file or directory
Error: Failed to read module directory
Module directory does not exist or cannot be read.
Error: Unreadable module directory
Unable to evaluate directory symlink: lstat foobar: no such file or directory
Error: Failed to read module directory
Module directory does not exist or cannot be read.
What should you do?
Possible Solution #1
1. Run this Linux command from the directory you ran the terraform command: grep -iR source *
2. Look at the source value in the file that you find. There should be a stanza like the one below.
source = "./foobar/submod"
Is the source a valid path relative to where the file is that has this stanza?
3. Verify that above path exists by running ls -lh ./foobar/submod
(Substitute "./foobar/submod" with the value you found.) In a .tf or .tf.json file your source path is probably wrong if you are getting the error above.
Possible Solution #2
Are you using variables files? You may need to check those. Are you using different environments (such as Dev, QA, production)? Perhaps your .tf files are configured properly for one environment but not another.
Possible Solution #3
The "terraform apply" command will update a tfstate file (terraform.tfstate). You may need to check those. Are you using terraform remote state? You may need to verify the remote state is accessible.
Possible Solution #4
Are you using different projects (directories where you run the "init" command)? You may need to check your configuration or verify the directory that you are in when you ran the offending command.
Special thanks to Don Gillies for bringing up improvements for this article.
Thanks for this post. I was running into this exact issue while porting a module over from another terraform codebase. This helped me find the root cause of the problem.
When I run “grep -iR source *” I get many things returned.
Then go to step 2.
Thank you – very helpful.