profile
viewpoint

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: https://www.terraform.io/community.html.

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

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.global = 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
directory


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
hashicorp/terraform

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 module.ssai.module.ssai.provider.aws
useful!

Related questions

failed to save provider manifest: open .terraform/plugins/linux_amd64/lock.json: permission denied hot 4
The argument "host" is required, but no definition was found. hot 3
Unable to run 0.12upgrade hot 3
Module cannot find alias AWS provider in 0.12.0 hot 3
Error: Invalid template interpolation value hot 2
Terraform v0.11.1 : Error downloading modules: Error loading modules: open .terraform/modules/3f10921295c292995128e9e36eb: no such file or directory hot 2
MalformedPolicyDocument: Policy document should not specify a principal. hot 2
Error in Terraform 0.12.0: This object has no argument, nested block, or exported attribute hot 2
Feature Request - Allow list/array in 'query' in 'external' data source hot 2
Terraform provider downloads fail with TLS handshake timeout hot 2
'terraform init' failed with 'Registry service unreachable.' error hot 2
for_each attribute for creating multiple resources based on a map hot 2
Provider Development: Expected type 'string', got unconvertible type '[]interface {}' - with complicated block hot 2
"Error: Provider configuration not present" when aliased provider is used hot 2
Error loading state: state snapshot was created by Terraform v0.12.7, which is newer than current v0.12.6 hot 2
Github User Rank List