antonbabenko / pre-commit-terraform

pre-commit git hooks to take care of Terraform configurations 🇺🇦
MIT License
3.21k stars 539 forks source link

tflint hangs when run from pre-commit #456

Closed declan-morris closed 1 year ago

declan-morris commented 1 year ago

Describe the bug

Latest version of Tflint hangs when running pre-commit. Left for over an hour and it can only be cancelled with a CTRL+C. I've installed a previously working version (v0.41.0) and it works fine.

For anyone else experiencing this issue, the below works correctly.

export TFLINT_VERSION=v0.41.0
curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash

How can we reproduce it?

Download latest tflint as of this bug report that's v0.43.0 and does not work with pre-commit. Running tflint manually via the cli on a folder with terraform files does work so it appears it's just pre-commit and tflint issue rather than a tflint issue?

export TFLINT_VERSION=v0.43.0
curl -s https://raw.githubusercontent.com/terraform-linters/tflint/master/install_linux.sh | bash
# run hook 
pre-commit run terraform_tflint -a

Result is that it hangs on and does not output anything

> pre-commit run terraform_tflint -a
Terraform validate with tflint...........................................
Logs ```bash version information `` pre-commit version: 2.20.0 git --version: git version 2.25.1 sys.version: 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0] sys.executable: /usr/bin/python3 os.name: posix sys.platform: linux `` ### error information `` Interrupted (^C): KeyboardInterrupt: `` `` Traceback (most recent call last): File "/home/dtm/.local/lib/python3.8/site-packages/pre_commit/error_handler.py", line 73, in error_handler yield File "/home/dtm/.local/lib/python3.8/site-packages/pre_commit/main.py", line 386, in main return run(args.config, store, args) File "/home/dtm/.local/lib/python3.8/site-packages/pre_commit/commands/run.py", line 426, in run return _run_hooks(config, hooks, skips, args) File "/home/dtm/.local/lib/python3.8/site-packages/pre_commit/commands/run.py", line 285, in _run_hooks current_retval, prior_diff = _run_single_hook( File "/home/dtm/.local/lib/python3.8/site-packages/pre_commit/commands/run.py", line 192, in _run_single_hook retcode, out = language.run_hook(hook, filenames, use_color) File "/home/dtm/.local/lib/python3.8/site-packages/pre_commit/languages/script.py", line 20, in run_hook return helpers.run_xargs(hook, cmd, file_args, color=color) File "/home/dtm/.local/lib/python3.8/site-packages/pre_commit/languages/helpers.py", line 134, in run_xargs return xargs(cmd, file_args, **kwargs) File "/home/dtm/.local/lib/python3.8/site-packages/pre_commit/xargs.py", line 164, in xargs for proc_retcode, proc_out, _ in results: File "/home/dtm/.local/lib/python3.8/site-packages/pre_commit/xargs.py", line 156, in run_cmd_partition return cmd_fn( File "/home/dtm/.local/lib/python3.8/site-packages/pre_commit/util.py", line 224, in cmd_output_p bts = os.read(pty.r, 4096) KeyboardInterrupt `` ```

Environment information

Linux DPW00000059 4.4.0-18362-Microsoft #1-Microsoft Mon Mar 18 12:02:00 PST 2019 x86_64 x86_64 x86_64 GNU/Linux
bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
pre-commit 2.20.0
Terraform v1.3.2
Python 3.8.10
checkov 2.1.270
terraform-docs version v0.16.0 1f686b1 linux/amd64
terragrunt SKIPPED
terrascan version: v1.15.2
TFLint version 0.43.0
+ ruleset.terraform (0.2.1-bundled)
tfsec v1.28.0
tfupdate tfupdate SKIPPED
hcledit hcledit SKIPPED
file content ```bash - repo: https://github.com/antonbabenko/pre-commit-terraform rev: v1.76.0 hooks: - id: terraform_fmt - id: terraform_docs files: 'modules/.*' args: - --hook-config=--path-to-file=README.md - --hook-config=--add-to-existing-file=true - --hook-config=--create-file-if-not-exist=true - id: terraform_tflint args: - --args=--enable-rule=terraform_documented_variables - --args=--enable-rule=terraform_documented_outputs - id: terraform_checkov ```
MaxymVlasov commented 1 year ago

Same repo, +- same conditions (could vary up to +-20seconds)

TFLint version 0.41.0: 3m 10s TFLint version 0.42.0: 7m 41s TFLint version 0.42.1: 8m 46s TFLint version 0.42.2: 8m 32s TFLint version 0.43.0: 7m 37s TFLint version 0.44.0: 2m 48s TFLint version 0.44.1: 2m 53s

Resolution: Just do not use TFLint version between 0.42.0 and 0.43.0 because they have performance issues