-
Notifications
You must be signed in to change notification settings - Fork 358
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
Add --recursive option #1622
Add --recursive option #1622
Conversation
24c32ad
to
d4e0df0
Compare
@bendrucker Any thoughts on this? |
Will review either today or tomorrow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Few small comments.
While reviewing this, it occurred to me that TFLint could potentially run faster in large repositories by inspecting modules in parallel. Using Chdir
will make that difficult. Not sure there's any viable alternative given that some Terraform modules depend on the working directory.
cmd/inspect.go
Outdated
} | ||
|
||
return ExitCodeOK | ||
if err := proc(); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If proc()
fails, the working directory is never reset to its original value. It should probably be reset regardless of the inner result. Since modules are processed in series I don't think this would have any impact right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Initially, I thought that if an error occurred, it should be returned to the caller without any changes, but It's obviously counterintuitive that the directory is changed outside of withinChangedDir
.
Co-authored-by: Ben Drucker <[email protected]>
Thank you for your review!
Yes, this would be difficult because it doesn't allow you to assign a different working directory to each goroutine. I would like to implement it naively first, and consider countermeasures if this becomes a problem in many projects. One possible idea is to reimplement the Another idea is to spawn a new process with This works well in high-CPU machines but has an issue of inconvenient aggregation of errors and results. |
Fixes #527
Fixes #1355
Closes #841
This PR adds
--recursive
option for inspection. This is useful in monorepo with multiple Terraform modules:In recursive mode, it walks each directory with
--chdir
. This means that it is roughly equivalent to the following shell script:See also #1612 for behavior regarding
--chdir
. In addition, there are some operational notes:.tflint.hcl
in each module.tflint --recursive --config=$(realpath .tflint.hcl)
terraform init
recursively.terraform init
recursively.tflint --init
recursively.format
andforce
in the config file are ignored in recursive mode. CLI flags are always respected.Finally, this recursive mode is not suitable for all projects. This is an experimental feature and the behavior may change frequently in future releases. If this is unacceptable, it is safe to implement a shell script using
--chdir
.