Ask questions`Unreadable module directory` error is not clear for nested modules

<!-- Hi there,

Thank you for opening an issue. Please note that we try to keep the Terraform issue tracker reserved for bug reports and feature requests. For general usage questions, please see:

If your issue relates to a specific Terraform provider, please open it in the provider's own repository. The index of providers is at . -->

Terraform Version

<!--- Run terraform -v to show the version, and paste the result between the ``` marks below.

If you are not running the latest version of Terraform, please try upgrading because your issue may have already been fixed. -->

Terraform v0.12.8

Terraform Configuration Files

<!-- Paste the relevant parts of your Terraform configuration between the ``` marks below.

For large Terraform configs, please use a service like Dropbox and share a link to the ZIP file. For security, you can also encrypt the files using our GPG public key. -->

module "aws_global" {
  providers = { = aws
  source = "../modules/aws-data/global"

  env     = var.env
  product = var.product

Note that the correct source is source = "../../../modules/aws-data/global"

Crash Output

<!-- If the console output indicates that Terraform crashed, please share a link to a GitHub Gist containing the output of the crash.log file. -->

terraform init
Initializing modules...
- ssai.api in ssai/api
- ssai.api.aws_global in
- ssai.api.names in ../modules/names

Error: Unreadable module directory

Unable to evaluate directory symlink: lstat ssai/modules: no such file or

Error: Failed to read module directory

Module directory  does not exist or cannot be read.

Note that the crash is much more verbose and repetitive than this, but this is the relevant part.

Expected Behavior

<!-- What should have happened? --> Reading the crash output, it should be clear which module was trying to be loaded which will make it easy to fix the situation. There is a tell in that - ssai.api.aws_global in doesn't have anything after in - but you have to know that and carefully look for it because it's not the last line.

I would expect the output to have the full address of the module that failed to load - in brief, something like this:

Error: Unreadable module directory

Failed to load module ssai.api.aws_global: Unable to evaluate directory symlink: lstat ssai/modules: no such file or directory

Another thing that could be improved is that the errors are repeated for every level of module nesting until it reaches the top. I don't know how your logging is structured, but if possible I think it would make sense to coalesce all the errors into one error that is printed at the top level that then has the full context I'm suggesting, rather than repeating the same error with no context.

Actual Behavior

See crash log

Steps to Reproduce

<!-- Please list the full steps required to reproduce the issue, for example:

  1. terraform init
  2. terraform apply -->
  • Create a series of nested modules
  • Set a nested module with an incorrect source
  • Run terraform init
  • Resulting crash will not have a clear context on which module had an incorrect source

Answer questions dmikalova

An example of this done right is when a provider is missing:

Initializing provider plugins...

Terraform has been successfully initialized!

Error: missing provider
Github User Rank List