Closed walkerk1980 closed 1 week ago
Issue appears to be started occurring from v1.90.0 when custom tf / tofu path is introduced.
@walkerk1980 Can you please try the fix in #714?
@walkerk1980 Can you please try the fix in #714?
The quoting $tf_path on line 52 of hooks/terraform_fmt.sh does indeed fix the first instance of the error.
'terraform init' failed, '/home/user1/work/applications/it_infra_tf_ccoe_app_bstrp_test/path/w ith/space/terraform validate' skipped: .
/home/user1/.cache/pre-commit/reposq7m00vx/hooks/_common.sh: line 539: /home/user1/work/applications/it_infra_tf_ccoe_app_bstrp_test/path/w: No such file or directory
Validation failed: terraform
/home/user1/.cache/pre-commit/reposq7m00vx/hooks/terraform_validate.sh: line 135: /home/user1/work/applications/it_infra_tf_ccoe_app_bstrp_test/path/w: No such file or directory
My errors are fixed entirely after quoting all unquoted instances of $tf_path in both hooks/_common.sh and hooks/terraform_validate.sh. Note that I did not need to quote all instances to get successful result, only the line numbers mentioned in the errors above, but was still successful after quoting all instances of the variable that were not within double quotes.
My errors are fixed entirely after quoting all unquoted instances of $tf_path in both hooks/_common.sh and hooks/terraform_validate.sh. Note that I did not need to quote all instances to get successful result, only the line numbers mentioned in the errors above, but was still successful after quoting all instances of the variable that were not within double quotes.
Would you mind contributing fix via PR (if @robinbowes doesn't object as he already started the #417)?
«quoting all instances of the variable that were not within double quotes» — this is the way to go if you go with PR. Thanks
PS: https://github.com/antonbabenko/pre-commit-terraform/pull/714#issuecomment-2332565074
My errors are fixed entirely after quoting all unquoted instances of $tf_path in both hooks/_common.sh and hooks/terraform_validate.sh. Note that I did not need to quote all instances to get successful result, only the line numbers mentioned in the errors above, but was still successful after quoting all instances of the variable that were not within double quotes.
Would you mind contributing fix via PR (if @robinbowes doesn't object as he already started the #417)?
«quoting all instances of the variable that were not within double quotes» — this is the way to go if you go with PR. Thanks
PS: #714 (comment)
Sure if the existing PR does not get updated by @robinbowes I can probably submit a PR tomorrow.
This issue has been resolved in version 1.94.2 :tada:
Describe the bug
Terraform hook fails when the terraform binary's path contains a space.
How can we reproduce it?
Do you have long logs to share? Please use collapsible sections, that can be created via:
LOGS
```bash $ ${PWD}/path/to/terraform -v Terraform v1.9.3 on linux_amd64 + provider registry.terraform.io/hashicorp/null v3.2.2 ``` ```bash $ ${PWD}/path/w\ ith/space/terraform -v Terraform v1.9.3 on linux_amd64 + provider registry.terraform.io/hashicorp/null v3.2.2 ``` ```bash $ export PCT_TFPATH="${PWD}/path/to/terraform"; pre-commit run --all check yaml...............................................................Passed check for added large files..............................................Passed check for case conflicts.................................................Passed check json...........................................(no files to check)Skipped check for merge conflicts................................................Passed check for broken symlinks................................................Passed detect destroyed symlinks................................................Passed detect private key.......................................................Passed terraform-docs...........................................................Passed Terraform fmt............................................................Passed ``` ```bash $ export PCT_TFPATH="${PWD}/path/w ith/space/terraform"; pre-commit run --all check yaml...............................................................Passed check for added large files..............................................Passed check for case conflicts.................................................Passed check json...........................................(no files to check)Skipped check for merge conflicts................................................Passed check for broken symlinks................................................Passed detect destroyed symlinks................................................Passed detect private key.......................................................Passed terraform-docs...........................................................Passed Terraform fmt............................................................Failed - hook id: terraform_fmt - exit code: 127 /home/user1/.cache/pre-commit/repo2_2krz94/hooks/terraform_fmt.sh: line 52: /home/user1/work/applications/it_infra_tf_ccoe_app_bstrp_test/path/w: No such file or directory /home/user1/.cache/pre-commit/repo2_2krz94/hooks/terraform_fmt.sh: line 52: /home/user1/work/applications/it_infra_tf_ccoe_app_bstrp_test/path/w: No such file or directory /home/user1/.cache/pre-commit/repo2_2krz94/hooks/terraform_fmt.sh: line 52: /home/user1/work/applications/it_infra_tf_ccoe_app_bstrp_test/path/w: No such file or directory /home/user1/.cache/pre-commit/repo2_2krz94/hooks/terraform_fmt.sh: line 52: /home/user1/work/applications/it_infra_tf_ccoe_app_bstrp_test/path/w: No such file or directory /home/user1/.cache/pre-commit/repo2_2krz94/hooks/terraform_fmt.sh: line 52: /home/user1/work/applications/it_infra_tf_ccoe_app_bstrp_test/path/w: No such file or directory /home/user1/.cache/pre-commit/repo2_2krz94/hooks/terraform_fmt.sh: line 52: /home/user1/work/applications/it_infra_tf_ccoe_app_bstrp_test/path/w: No such file or directory /home/user1/.cache/pre-commit/repo2_2krz94/hooks/terraform_fmt.sh: line 52: /home/user1/work/applications/it_infra_tf_ccoe_app_bstrp_test/path/w: No such file or directory /home/user1/.cache/pre-commit/repo2_2krz94/hooks/terraform_fmt.sh: line 52: /home/user1/work/applications/it_infra_tf_ccoe_app_bstrp_test/path/w: No such file or directory Terraform validate.......................................................Failed - hook id: terraform_validate - exit code: 127 'terraform init' failed, '/home/user1/work/applications/it_infra_tf_ccoe_app_bstrp_test/path/w ith/space/terraform validate' skipped: . /home/user1/.cache/pre-commit/repo2_2krz94/hooks/_common.sh: line 539: /home/user1/work/applications/it_infra_tf_ccoe_app_bstrp_test/path/w: No such file or directory Validation failed: terraform /home/user1/.cache/pre-commit/repo2_2krz94/hooks/terraform_validate.sh: line 135: /home/user1/work/applications/it_infra_tf_ccoe_app_bstrp_test/path/w: No such file or directory ```Environment information
OS:
Bug is present on both Windows and Linux (initially discovered on Windows due to "Program Files" in path).
uname -a
and/orsysteminfo | Select-String "^OS"
output:.pre-commit-config.yaml
:file content
```yaml repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.6.0 hooks: # - id: trailing-whitespace # - id: end-of-file-fixer - id: check-yaml - id: check-added-large-files - id: check-case-conflict - id: check-json - id: check-merge-conflict - id: check-symlinks - id: destroyed-symlinks # - id: detect-aws-credentials - id: detect-private-key - repo: https://github.com/terraform-docs/terraform-docs rev: "v0.18.0" hooks: - id: terraform-docs-go args: ["markdown", "--output-file", "../README.md", "terraform"] - repo: https://github.com/antonbabenko/pre-commit-terraform rev: "v1.94.1" hooks: - id: terraform_fmt args: ["terraform"] - id: terraform_validate args: ["terraform"] ```