Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terraform validate has "Failed to read module directory" when using nested modules #139

Closed
nshenry03 opened this issue Aug 28, 2020 · 2 comments

Comments

@nshenry03
Copy link
Contributor

I am using nested modules as recommended by Terraform; however, I was running into this error:

hnicholas@hnicholas-a01:~/Repositories/velocloud-terraform-modules$ pre-commit run
Terraform fmt............................................................Passed
Terraform validate.......................................................Failed
- hook id: terraform_validate
- exit code: 1


Error: Failed to read module directory

Module directory ../../../../../modules/security_groups does not exist or
cannot be read.


Failed path: terraform-aws-velocloud-uag/modules/security_groups
================================

Terraform docs...........................................................Passed
Terraform validate with tflint...........................................Passed
Terraform validate with tfsec............................................Passed

I was able to work around the issue by updating .cache/pre-commit/repo<some random string>/terraform_validate.sh:

--- /Users/hnicholas/.cache/pre-commit/repov0zt08cv/terraform_validate.sh.bak   2020-08-28 17:24:34.000000000 -0600
+++ /Users/hnicholas/.cache/pre-commit/repov0zt08cv/terraform_validate.sh       2020-08-28 17:05:20.000000000 -0600
@@ -97,6 +97,7 @@ terraform_validate_() {

       local validate_path
       validate_path="${path_uniq#"$terraform_path"}"
+      validate_path="${validate_path#/}"

       # Change to the directory that has been initialized, run validation, then
       # change back to the starting directory.

I'm sure there's a cleaner way as part of validate_path="${path_uniq#"$terraform_path"}" but I don't have the time to dig deeper tonight... Hopefully this is an easy fix or this helps others.

Thanks!


Version Information

hnicholas@hnicholas-a01:~/Repositories/velocloud-terraform-modules/terraform-aws-velocloud-vce$ terraform --version
Terraform v0.12.29
+ provider.aws v3.4.0
+ provider.time v0.5.0

Your version of Terraform is out of date! The latest version
is 0.13.1. You can update by downloading from https://www.terraform.io/downloads.html


hnicholas@hnicholas-a01:~/Repositories/velocloud-terraform-modules/terraform-aws-velocloud-vce$ pre-commit --version
pre-commit 2.7.1


hnicholas@hnicholas-a01:~/Repositories/velocloud-terraform-modules/terraform-aws-velocloud-vce$ cat ../.pre-commit-config.yaml
repos:
- repo: git://github.com/antonbabenko/pre-commit-terraform
  rev: v1.35.0
  hooks:
    - id: terraform_fmt
    - id: terraform_validate
    - id: terraform_docs
    - id: terraform_tflint
    - id: terraform_tfsec


hnicholas@hnicholas-a01:~/Repositories/velocloud-terraform-modules/terraform-aws-velocloud-vce$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.15.6
BuildVersion:   19G2021
@antonbabenko
Copy link
Owner

Hi @nshenry03 !

Thanks for opening this issue.

I think this problem has been described and fixed in #141. Please update to v1.38.0 and tell if the problem is still there.

@nshenry03
Copy link
Contributor Author

Awesome, thanks, I'll try it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants