Problem with dependant module resolution if the path is relative
Problem
Terraform Version 0.12.13 Terraform Configuration Files Here you can see two examples: https://github.com/xocasdashdash/terraform-test-case One works perfectly with 0.11, same one fails on 0.12.13 (and on dev too). Debug Output [code block] Expected Behavior It should resolve to the correct module path for the "d-module". Actual Behavior It does not. But if I change the route to use a local symlink and add a double "//" on the last folder before the module folder "//a-module" and set up a symlink from the module to the parent folder it does work correctly. Steps to Reproduce Run terraform init in each of the three folders with the last working version (0.11.14 and 0.12.13). Additional Context I've tried to fix it myself and I think the fix should go to this function: https://github.com/hashicorp/terraform/blob/6f66aad03262441521829ca3a678da2bb6bf51d9/internal/initwd/module_install.go#L226 I'm gonna try some more to make it work but I believe a bigger change will be needed to get this to work in all cases
Error Output
Error: Unreadable module directory
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Fix Relative Module Path Resolution in Terraform 0.12.13
In Terraform 0.12.13, the handling of relative module paths has changed from version 0.11. This change affects how module directories are resolved, leading to errors when the paths are not absolute or incorrectly formatted. The error 'Unreadable module directory' indicates that Terraform cannot locate the specified module due to these path resolution issues.
Awaiting Verification
Be the first to verify this fix
- 1
Update Module Path Syntax
Modify the module path in your Terraform configuration files to use absolute paths or ensure that relative paths are correctly formatted. Replace instances of relative paths that may lead to ambiguity.
hclmodule "d-module" { source = "../a-module" } - 2
Use Symlinks for Local Development
If you are developing locally and need to reference modules, create symlinks for the module directories. This can help in resolving paths correctly. Use the following command to create a symlink in your terminal.
bashln -s /path/to/a-module /path/to/d-module/a-module - 3
Run Terraform Init
After updating the module paths and creating symlinks, run 'terraform init' in each of the affected directories to reinitialize the Terraform working directory and download the modules.
bashterraform init - 4
Validate Configuration
Run 'terraform validate' to ensure that the configuration is valid and that all modules are being correctly resolved. This will help identify any remaining issues with module paths.
bashterraform validate
Validation
Confirm that the module paths are resolved correctly by running 'terraform plan' without any errors. The expected behavior is that Terraform should not output any 'Unreadable module directory' errors.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep