Closed avnerv closed 1 year ago
Please provide some_tf_file.tf
for minimal reproduction
I suppose just
local {}
?
some_tf_file
I suppose just
local {}
?
yep
Not reproduced, for provided by you .pre-commit-config.yaml
in Ubuntu. It could be Mac-only bug.
18:09 557 git:(main ?)
β ls -a
. .. .git .pre-commit-config.yaml main.tf
18:09 557 git:(main ?)
β cat main.tf
local {}
18:09 557 git:(main ?)
β pre-commit run terraform_validate --file=main.tf
Terraform validate.......................................................Failed
- hook id: terraform_validate
- exit code: 1
Error: Unsupported block type
on main.tf line 1:
1: local {}
Blocks of type "local" are not expected here. Did you mean "locals"?
'terraform init' failed, 'terraform validate' skipped: .
There are some problems with the configuration, described below.
The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.
β·
β Error: Unsupported block type
β
β on main.tf line 1:
β 1: local {}
β
β Blocks of type "local" are not expected here. Did you mean "locals"?
β΅
Please try next and post here a output:
mkdir /tmp/557 && cd /tmp/557
git init
echo "local {}" > main.tf
echo "
---
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.81.0
hooks:
- id: terraform_fmt
- id: terraform_validate
args:
- --args=-no-color
# no need to run terraform_validate on the modules
exclude: ^(hamc/hadc-customer-account/terraform/modules/|terraform-modules/)
- id: terraform_docs
args:
- --args=--config=.terraform-docs.yml
- --hook-config=--path-to-file=README.md
- --hook-config=--add-to-existing-file=true
- --hook-config=--create-file-if-not-exist=true
# duplicated terraform_tflint hook to workaround unused vars
# https://h2oai.slack.com/archives/C02PEQYERHS/p1692114976010729?thread_ts=1692114346.807749&cid=C02PEQYERHS
- id: terraform_tflint
args:
- --args=--only=terraform_deprecated_interpolation
- --args=--only=terraform_deprecated_index
- --args=--only=terraform_unused_declarations
- --args=--only=terraform_comment_syntax
- --args=--only=terraform_documented_outputs
- --args=--only=terraform_documented_variables
- --args=--only=terraform_typed_variables
- --args=--only=terraform_module_pinned_source
- --args=--only=terraform_workspace_remote
- --args=--only=terraform_unused_required_providers
exclude: ^(hamc/hadc-customer-account/terraform/environment/|hamc/hadc-customer-account/terraform/environment/aws/|hamc/hadc-customer-account/terraform/environment/k8s/|hamc/hadc-customer-account/terraform/environment/applications/)
- id: terraform_tflint
args:
- --args=--only=terraform_deprecated_interpolation
- --args=--only=terraform_deprecated_index
- --args=--only=terraform_comment_syntax
- --args=--only=terraform_documented_outputs
- --args=--only=terraform_documented_variables
- --args=--only=terraform_typed_variables
- --args=--only=terraform_module_pinned_source
- --args=--only=terraform_workspace_remote
- --args=--only=terraform_unused_required_providers
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-merge-conflict
- id: end-of-file-fixer
" > .pre-commit-config.yaml
git add -A
git commit -nm "init"
pre-commit run terraform_validate --file=main.tf
@MaxymVlasov, got it, even then, Iβd expect the second error message to be the output since it contains essential details for parsing.
Validation failed: hamc/hadc-customer-account/terraform/environment/aws
Error: Unsupported block type
on locals.tf line 1:
1: local {
Blocks of type "local" are not expected here. Did you mean "locals"?
I still don't understand how you get 2nd error msg. Please provide the minimal reproducible file with instructions on how you check it to get 2 same errors
Please try next and post here a output:
mkdir /tmp/557 && cd /tmp/557 git init echo "local {}" > main.tf echo " --- repos: - repo: https://github.com/antonbabenko/pre-commit-terraform rev: v1.81.0 hooks: - id: terraform_fmt - id: terraform_validate args: - --args=-no-color # no need to run terraform_validate on the modules exclude: ^(hamc/hadc-customer-account/terraform/modules/|terraform-modules/) - id: terraform_docs args: - --args=--config=.terraform-docs.yml - --hook-config=--path-to-file=README.md - --hook-config=--add-to-existing-file=true - --hook-config=--create-file-if-not-exist=true # duplicated terraform_tflint hook to workaround unused vars # https://h2oai.slack.com/archives/C02PEQYERHS/p1692114976010729?thread_ts=1692114346.807749&cid=C02PEQYERHS - id: terraform_tflint args: - --args=--only=terraform_deprecated_interpolation - --args=--only=terraform_deprecated_index - --args=--only=terraform_unused_declarations - --args=--only=terraform_comment_syntax - --args=--only=terraform_documented_outputs - --args=--only=terraform_documented_variables - --args=--only=terraform_typed_variables - --args=--only=terraform_module_pinned_source - --args=--only=terraform_workspace_remote - --args=--only=terraform_unused_required_providers exclude: ^(hamc/hadc-customer-account/terraform/environment/|hamc/hadc-customer-account/terraform/environment/aws/|hamc/hadc-customer-account/terraform/environment/k8s/|hamc/hadc-customer-account/terraform/environment/applications/) - id: terraform_tflint args: - --args=--only=terraform_deprecated_interpolation - --args=--only=terraform_deprecated_index - --args=--only=terraform_comment_syntax - --args=--only=terraform_documented_outputs - --args=--only=terraform_documented_variables - --args=--only=terraform_typed_variables - --args=--only=terraform_module_pinned_source - --args=--only=terraform_workspace_remote - --args=--only=terraform_unused_required_providers - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 hooks: - id: check-merge-conflict - id: end-of-file-fixer " > .pre-commit-config.yaml git add -A git commit -nm "init" pre-commit run terraform_validate --file=main.tf
the output:
hint: Using 'master' as the name for the initial branch. This default branch name
hint: is subject to change. To configure the initial branch name to use in all
hint: of your new repositories, which will suppress this warning, call:
hint:
hint: git config --global init.defaultBranch <name>
hint:
hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
hint: 'development'. The just-created branch can be renamed via this command:
hint:
hint: git branch -m <name>
Initialized empty Git repository in /private/tmp/557/.git/
[master (root-commit) 121d8bd] init
2 files changed, 51 insertions(+)
create mode 100644 .pre-commit-config.yaml
create mode 100644 main.tf
Terraform validate.......................................................Failed
- hook id: terraform_validate
- exit code: 1
Error: Unsupported block type
on main.tf line 1:
1: local {}
Blocks of type "local" are not expected here. Did you mean "locals"?
'terraform init' failed, 'terraform validate' skipped: .
There are some problems with the configuration, described below.
The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.
β·
β Error: Unsupported block type
β
β on main.tf line 1:
β 1: local {}
β
β Blocks of type "local" are not expected here. Did you mean "locals"?
β΅
β 557 git:(master)
Need some-one with Mac to debug and fix it
Ah, my bad, it reproducible in linux
The first error msg goes from
Second, from
If we add to example repo .terraform/modules/
and .terraform/providers/
to suppress second error, we got next:
Terraform validate.......................................................Failed
- hook id: terraform_validate
- exit code: 1
Error: Unsupported block type
on main.tf line 1:
1: local {}
Blocks of type "local" are not expected here. Did you mean "locals"?
Validation failed: .
Error: Unsupported block type
on main.tf line 1:
1: local {}
Blocks of type "local" are not expected here. Did you mean "locals"?
Which calculated from https://github.com/antonbabenko/pre-commit-terraform/blob/66a1469a7c7954d8469d7a6f79f4ffb8c9ae09bf/hooks/terraform_validate.sh#L130
That means, that we can simply suppress any logs from https://github.com/antonbabenko/pre-commit-terraform/blob/66a1469a7c7954d8469d7a6f79f4ffb8c9ae09bf/hooks/terraform_validate.sh#L116
This issue has been resolved in version 1.83.5 :tada:
Describe the bug
terraform_validate
hook prints the same error message twice:How can we reproduce it?
pre-commit run terraform_validate --file=some_tf_file.tf
Environment information
OS: MacOS
uname -a
and/orsysteminfo | Select-String "^OS"
output:.pre-commit-config.yaml
:file content
```bash --- repos: - repo: https://github.com/antonbabenko/pre-commit-terraform rev: v1.81.0 hooks: - id: terraform_fmt - id: terraform_validate args: - --args=-no-color # no need to run terraform_validate on the modules exclude: ^(hamc/hadc-customer-account/terraform/modules/|terraform-modules/) - id: terraform_docs args: - --args=--config=.terraform-docs.yml - --hook-config=--path-to-file=README.md - --hook-config=--add-to-existing-file=true - --hook-config=--create-file-if-not-exist=true # duplicated terraform_tflint hook to workaround unused vars # https://h2oai.slack.com/archives/C02PEQYERHS/p1692114976010729?thread_ts=1692114346.807749&cid=C02PEQYERHS - id: terraform_tflint args: - --args=--only=terraform_deprecated_interpolation - --args=--only=terraform_deprecated_index - --args=--only=terraform_unused_declarations - --args=--only=terraform_comment_syntax - --args=--only=terraform_documented_outputs - --args=--only=terraform_documented_variables - --args=--only=terraform_typed_variables - --args=--only=terraform_module_pinned_source - --args=--only=terraform_workspace_remote - --args=--only=terraform_unused_required_providers exclude: ^(hamc/hadc-customer-account/terraform/environment/|hamc/hadc-customer-account/terraform/environment/aws/|hamc/hadc-customer-account/terraform/environment/k8s/|hamc/hadc-customer-account/terraform/environment/applications/) - id: terraform_tflint args: - --args=--only=terraform_deprecated_interpolation - --args=--only=terraform_deprecated_index - --args=--only=terraform_comment_syntax - --args=--only=terraform_documented_outputs - --args=--only=terraform_documented_variables - --args=--only=terraform_typed_variables - --args=--only=terraform_module_pinned_source - --args=--only=terraform_workspace_remote - --args=--only=terraform_unused_required_providers - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 hooks: - id: check-merge-conflict - id: end-of-file-fixer ```