-
-
Notifications
You must be signed in to change notification settings - Fork 541
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 fmt being run in .terraform dir #8
Comments
Make sure that you are using correct version of the hook. Also, you can try to clean |
I am using the latest version of the hook (1.4.0). But I do still get this behaviour. If I have an existing tf repo with a .terraform dir and I run I'll check if there is a verbose/debug mode for pre-commit to see if it's apparent why this happens for me. |
Do you have In fact it should not be related to the issue you specify, because those files should be ignored by pre-commit hook. |
Yeah I always include I wonder if this is perhaps a pre-commit issue rather than an issue with this hook where (for me) it is not ignoring the files it is meant to...? Still testing (in between real job! 😁) |
pre-commit passes the correct set of files to However,
These directories are then passed to If there exists a Why is |
This can be replicated by creating a directory with the following structure:
where
The standard pre-commit requirements will need to be performed (install pre-commit, terraform, this hook, git stuff, etc). Running
|
I can confirm the behaviour reported by @samgd . |
If that sounds acceptable I would be happy to start a PR? edit: I've just realised that unless pre-commit sends a list of changed files we can't act on that subset of files. I haven't looked into the internals of pre-commit yet so I'm not sure if it's possible to act only on the files changed in a commit. It could be a case of all or nothing... 🤔 |
@sysadmiral @samgd thanks for keeping this issue alive :) pre-commit sends a list of changed files to process to the hook, and then the hook ( I wonder whether pre-commit tracks changes in Does If |
Are there any updates on this issue? I see the same issue with tfsec not ignoring the .terraform directory. |
Not reproduced for 22:17 test-8 git:(main +)
➜ ls -lah
total 140K
drwxr-xr-x 4 vm vm 4.0K Sep 9 22:15 .
drwxrwxrwt 62 root root 120K Sep 9 22:15 ..
drwxr-xr-x 5 vm vm 4.0K Sep 9 22:17 .git
-rw-r--r-- 1 vm vm 112 Sep 9 22:14 .pre-commit-config.yaml
drwxr-xr-x 2 vm vm 4.0K Sep 9 22:14 .terraform
-rw-r--r-- 1 vm vm 0 Sep 9 22:14 valid.tf
22:17 test-8 git:(main +)
➜ ls -lah .terraform
total 12K
drwxr-xr-x 2 vm vm 4.0K Sep 9 22:14 .
drwxr-xr-x 4 vm vm 4.0K Sep 9 22:15 ..
-rw-r--r-- 1 vm vm 9 Sep 9 22:14 invalid.tf
22:17 test-8 git:(main +)
➜ find . -maxdepth 1 -type f -exec cat {} \;
repos:
- repo: git://github.com/antonbabenko/pre-commit-terraform
rev: v1.50.0
hooks:
- id: terraform_fmt
22:18 test-8 git:(main +)
➜ find ./.terraform -maxdepth 1 -type f -exec cat {} \;
invalid
22:18 test-8 git:(main +)
➜ git status
On branch main
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: .pre-commit-config.yaml
new file: .terraform/invalid.tf
new file: valid.tf
22:19 test-8 git:(main +)
➜ pre-commit run -a
Terraform fmt............................................................Passed
22:19 test-8 git:(main +)
➜ pre-commit --version
pre-commit 2.14.0
22:19 test-8 git:(main +)
➜ terraform --version | head -n 1
Terraform v1.0.6
22:19 test-8 git:(main +)
➜ |
And not reproduced for 22:25 test-8 git:(main +)
➜ pre-commit run -a
Terraform validate with tfsec............................................Passed Feel free to reopen the issue with details about your environment and reproduction steps if the issue is still present. |
Not sure why yet but this hook runs in the
.terraform
dir for me but from the code it looks like that dir should be ignored?I will investigate further and post an update.
The text was updated successfully, but these errors were encountered: