Terraform: `Unreadable module directory` error is not clear for nested modules

Created on 12 Sep 2019  路  6Comments  路  Source: hashicorp/terraform

Terraform Version

Terraform v0.12.8

Terraform Configuration Files

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

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


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

  • 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
cli enhancement

Most helpful comment

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

All 6 comments

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

I'm getting something similar, wondering if you made any progress on this since it's been a few months. I was working locally for awhile and moved to Terraform Cloud which is working fine. I created a new local directory, copied over the root files over from my current project and changed all the sources to local directories for testing out modules before pushing them to my module registry. This is when I started getting the "Unreadable Module Directory" although the path is correct. I've tried the Absolute Path and Relative Path, changed the permissions on the module directories to full access with no change. Not sure what happened here, running Terraform v0.12.21

Copying to my Virtual Box and running Terraform init there works fine using the same path and same version of Terraform.

azure\infrastructure\salt-master-test> terraform init
Initializing modules...
- return_prefixes in 
- salt-master_asg in ..\..\modules\security\asg
- salt-master_nsg in ..\..\modules\security\nsg
- salt-master_private_subnet in ..\..\modules\networking\virtual_subnet
- salt-master_vms in ..\..\modules\compute\linux_vm
- saltmaster_share in ..\..\modules\storage\storage_share

Error: Unreadable module directory

Unable to evaluate directory symlink: CreateFile ..\..\modules\data_function:
The system cannot find the file specified.


Error: Failed to read module directory

Module directory  does not exist or cannot be read.


Error: Unreadable module directory

Unable to evaluate directory symlink: CreateFile ..\..\modules\data_function:
The system cannot find the file specified.


Error: Failed to read module directory

Module directory  does not exist or cannot be read.


Error: Unreadable module directory

Unable to evaluate directory symlink: CreateFile ..\..\modules\data_function:
The system cannot find the file specified.


Error: Failed to read module directory

Module directory  does not exist or cannot be read.


Error: Unreadable module directory

Unable to evaluate directory symlink: CreateFile ..\..\modules\data_function:
The system cannot find the file specified.


Error: Failed to read module directory

Module directory  does not exist or cannot be read.


Error: Unreadable module directory

Unable to evaluate directory symlink: CreateFile ..\..\modules\data_function:
The system cannot find the file specified.


Error: Failed to read module directory

Module directory  does not exist or cannot be read.


Error: Unreadable module directory

Unable to evaluate directory symlink: CreateFile ..\..\modules\data_function:
The system cannot find the file specified.


Error: Failed to read module directory

Module directory  does not exist or cannot be read.


Error: Unreadable module directory

Unable to evaluate directory symlink: CreateFile ..\..\modules\data_function:
The system cannot find the file specified.


Error: Failed to read module directory

Module directory  does not exist or cannot be read.
azure\infrastructure\salt-master-test>  ls ..\..\


    Directory: F:\Terraform\providers\azure


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        2/24/2020   3:14 PM                infrastructure
d-----        2/24/2020   2:30 PM                modules

+1 for this, as it's impossible in a complicated project to diagnose issues with this output.

it's giving same error for me as well, it has some bugs.

I figured out this is related to terraform version constraint in file. This has something to do with the fact that only public terraform repositories are allowed to have versioning constraints You can load private modules directly from version control and other sources, but those sources don't support version constraints

To make long story short, if you remove this part from your *.tf file:

terraform { required_version = ">= 0.12" }

you may reference modules now via relative path.

Would've been great to have string concatenation in hcl to be able to use ${path.module}+"/path/to/module" construct for example, anyone has an idea if that's possible?

@dmikalova @shlubz

You are using Terraform Cloud, so you must specify the working directory for your workspace.

Was this page helpful?
0 / 5 - 0 ratings