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

Feature Request: Look for .tflint.hcl in repository root directory #1408

Closed
gtirloni opened this issue Jun 3, 2022 · 6 comments
Closed

Feature Request: Look for .tflint.hcl in repository root directory #1408

gtirloni opened this issue Jun 3, 2022 · 6 comments

Comments

@gtirloni
Copy link

gtirloni commented Jun 3, 2022

Currently, tflint looks for .tflint.hcl files in:

  • $PWD/.tflint.hcl
  • $HOME/.tflint.hcl

For monorepos with many environments, it would be useful if tflint would go to the repository root and use the .tflint.hcl from that location. This would allow projects to set repository-wide linting rules.

@bendrucker
Copy link
Member

TFLint doesn't have awareness of version control or (Git) repositories.

What I've proposed in the past that would address this use case is traversing upwards from the working directory until a file is encountered. Optionally, it could continue all the way up to /, merging accumulated child directories' config into the parent. The latter would allow for a repository to define repo-level defaults at the repo root while enabling modules to override specific configuration values.

@gtirloni
Copy link
Author

gtirloni commented Jun 7, 2022

Yes, that would be great. Although I would prefer that it stopped at the repository root and didn't continue outside of it to avoid some unpredictable situations (e.g. with Vagrant, a user could have settings in anywhere that would conflict with what the repository had defined -- I think the repository root should have the final say).

@bendrucker
Copy link
Member

Noted, but I'm telling you that coupling TFLint to one or more version control systems is a non-starter. TFLint operates at the level of Terraform modules.

If you want to couple TFLint to git, for example, you'll need to do that at the user level:

tflint --config "$(git rev-parse --show-toplevel)/.tflint.hcl"

Navigating upwards and merging allows you to ship an image (e.g. Docker, Vagrant box) that contains a set of defaults in / or ~ while allowing users to override specific settings in a single module.

Presumably setting --config would disable this behavior and authoritatively select a single configuration file, meaning the approach above will continue to give you your desired behavior even if upward walking/merging is added.

@gtirloni
Copy link
Author

gtirloni commented Jun 8, 2022

I have a monorepo with many environments that share a .tflint.hcl file at the root of said repository.

Thanks for the suggestion, I'll add a alias to my shell configuration. I still think it'd be a better user experience if tflint would automatically do that, like other tools, but I understand the desire to have it independent from any version control.

@gtirloni gtirloni closed this as completed Jun 8, 2022
@bendrucker
Copy link
Member

bendrucker commented Jun 8, 2022

The walk up feature is definitely planned, this is a good reminder for me to pick it back up and get a PR up. Ultimately both that feature and composing with the git CLI should work, identically in the vast majority of cases. It is certainly reasonable to include some examples in the docs on how to explicitly grab config relative to VCS, eg git, hg.

Another idea here that you'd probably find appealing is adding root = true to the config. When walking up and merging config, this attribute would indicate that walking up for config should be halted. Unlike VCS integration, this has the added benefit of allowing specific non-root modules to declaratively prevent inheritance of parent configuration.

@gtirloni
Copy link
Author

gtirloni commented Jun 9, 2022

Thanks for the root suggestion, that's indeed very nice.

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

No branches or pull requests

2 participants