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

terraform_docs hook broken in v1.92.2 #699

Closed
Shr3ps opened this issue Aug 23, 2024 · 10 comments
Closed

terraform_docs hook broken in v1.92.2 #699

Shr3ps opened this issue Aug 23, 2024 · 10 comments

Comments

@Shr3ps
Copy link

Shr3ps commented Aug 23, 2024

Describe the bug

Using the latest version of the hook (v1.92.2), pre-commit is always in "PASSED" state even if we change variables, outputs or versions constrains.

How can we reproduce it?

vim versions.tf
sed -i 's/version = "~> 3.80"/version = "~> 3.86"/g' versions.tf
pre-commit run -a

Terraform fmt...........................................................................Passed
Terraform docs..........................................................................Passed

It should failed and update README.md file.

Environment information

  • OS:

OS: Win11 with Ubuntu 20.04 on WSL2
OS: Ubuntu 20.04

  • Docker image tag/git commit: v1.92.2

  • .pre-commit-config.yaml:

file content
  25   │   - repo: https://github.com/antonbabenko/pre-commit-terraform.git
  26   │     rev: v1.92.2
  27   │     hooks:
  28   │       - id: terraform_fmt
  29   │         stages: [pre-commit]
  30   │       - id: terraform_docs
  31   │         stages: [pre-commit]
  32   │         args:
  33   │           - --args=--config=.config/terraform-docs.yml
@Shr3ps Shr3ps added area/docker bug Something isn't working labels Aug 23, 2024
@Shr3ps
Copy link
Author

Shr3ps commented Aug 23, 2024

(everything is working as expected with v1.92.1)

@yermulnik
Copy link
Collaborator

Might probably be related to #698 🤔

@Shr3ps Would you please also share contents of the .config/terraform-docs.yml file?

@Shr3ps
Copy link
Author

Shr3ps commented Aug 23, 2024

Might probably be related to #698 🤔

@Shr3ps Would you please also share contents of the .config/terraform-docs.yml file?

Yep, here you go:

---
# This file is automatically maintained within this module repository -- DO NOT EDIT
formatter: "markdown"

settings:
  anchor: false
  lockfile: false

output:
  file: "README.md"

sections:
  hide: [requirements]

content: |-
  ## Global versioning rule for Claranet Azure modules

  | Module version | Terraform version | AzureRM version |
  | -------------- | ----------------- | --------------- |
  | >= 7.x.x       | 1.3.x             | >= 3.0          |
  | >= 6.x.x       | 1.x               | >= 3.0          |
  | >= 5.x.x       | 0.15.x            | >= 2.0          |
  | >= 4.x.x       | 0.13.x / 0.14.x   | >= 2.0          |
  | >= 3.x.x       | 0.12.x            | >= 2.0          |
  | >= 2.x.x       | 0.12.x            | < 2.0           |
  | <  2.x.x       | 0.11.x            | < 2.0           |

  ## Contributing

  If you want to contribute to this repository, feel free to use our [pre-commit](https://pre-commit.com/) git hook configuration
  which will help you automatically update and format some files for you by enforcing our Terraform code module best-practices.

  More details are available in the [CONTRIBUTING.md](./CONTRIBUTING.md#pull-request-process) file.

  ## Usage

  This module is optimized to work with the [Claranet terraform-wrapper](https://github.com/claranet/terraform-wrapper) tool
  which set some terraform variables in the environment needed by this module.
  More details about variables set by the `terraform-wrapper` available in the [documentation](https://github.com/claranet/terraform-wrapper#environment).

  ```hcl
  {{ include "examples/main/modules.tf" }}
  ```

  {{ .Providers }}

  {{ .Modules }}

  {{ .Resources }}

  {{ .Inputs }}

  {{ .Outputs }}
...

@yermulnik
Copy link
Collaborator

@Shr3ps Thank you.

@MaxymVlasov Need your brain here 🤷🏻

@MaxymVlasov
Copy link
Collaborator

As you used wrong bug template, @Shr3ps please provide info about environment.

* Tools availability and versions:
<!-- For check all needed version run next script:
bash << EOF
bash --version | head -n 1 2>/dev/null || echo "bash SKIPPED"
pre-commit --version 2>/dev/null || echo "pre-commit SKIPPED"
tofu --version | head -n 1 2>/dev/null || echo "opentofu SKIPPED"
terraform --version | head -n 1 2>/dev/null || echo "terraform SKIPPED"
python --version 2>/dev/null || echo "python SKIPPED"
python3 --version 2>/dev/null || echo "python3 SKIPPED"
echo -n "checkov " && checkov --version 2>/dev/null || echo "SKIPPED"
infracost --version 2>/dev/null || echo "infracost SKIPPED"
terraform-docs --version 2>/dev/null || echo "terraform-docs SKIPPED"
terragrunt --version 2>/dev/null || echo "terragrunt SKIPPED"
echo -n "terrascan " && terrascan version 2>/dev/null || echo "SKIPPED"
tflint --version 2>/dev/null || echo "tflint SKIPPED"
echo -n "tfsec " && tfsec --version 2>/dev/null || echo "SKIPPED"
echo -n "trivy " && trivy --version 2>/dev/null || echo "SKIPPED"
echo -n "tfupdate " && tfupdate --version 2>/dev/null || echo "SKIPPED"
echo -n "hcledit " && hcledit version 2>/dev/null || echo "SKIPPED"
EOF
-->
```bash
INSERT_TOOLS_VERSIONS_HERE
```

Because currently, I can't reproduce this issue.

But I found a minor issue that if output.file specified, warning always shown
image

@Shr3ps
Copy link
Author

Shr3ps commented Aug 26, 2024

Hello,

some steps to reproduce my issue:

$ git clone https://github.com/claranet/terraform-azurerm-rg/
$ cd terraform-azurerm-rg 
$ pre-commit install 
$ sed -i 's/>= 1.32/>= 1.33/g' versions.tf     
$ sed -i 's/Resource group name/Resource group name./g' outputs.tf
$ git add .
$ pre-commit run
$ git commit -m 'chore: test pre-commit'

the bug is that pre-commit outputs:

Terraform fmt...........................................................................Passed
Terraform docs..........................................................................Passed
Terraform validate......................................................................Passed
Terraform validate with tflint..........................................................Passed

but should fail on tfdoc step instead because of the changes done on .tf files.

Setting back v1.92.1 in the .pre-commit-config.yaml file and pre-commit is ok again (updating README.md / failing on the tfdoc step)

Environment information

  • $ uname -a
Linux FR-LAP822653786 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
  • Tools availability and versions:
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
pre-commit 3.7.0
OpenTofu v1.8.1
Terraform v1.5.3
python SKIPPED
Python 3.10.12
checkov SKIPPED
infracost SKIPPED
terraform-docs version v0.18.0 228c7a7 linux/amd64
terragrunt SKIPPED
terrascan version: v1.1.0
TFLint version 0.44.1
+ ruleset.terraform (0.2.2-bundled)
tfsec v1.28.1
trivy Version: 0.54.1
tfupdate SKIPPED
hcledit SKIPPED

@MaxymVlasov
Copy link
Collaborator

Default markers:
Screenshot from 2024-08-27 20-05-11
Your markers:
Screenshot from 2024-08-27 20-07-01

Documentation about that:
Screenshot from 2024-08-27 20-05-45

So you just need to set

      - id: terraform_docs
        args:
          - --args=--config=.config/terraform-docs.yml
          - --hook-config=--use-standard-markers=true

to work as expected.

I am not sure why it was able to work before 1.92.2, but that wasn't expected behavior.

We could release a new minor version which will include force change of markers to TF_DOCS default makers (they were introduced a few years later than in this repo, that's why they different), but that will not be a bug fix :)

@MaxymVlasov
Copy link
Collaborator

Also, check #701

@Shr3ps
Copy link
Author

Shr3ps commented Aug 28, 2024

Thanks @MaxymVlasov , I can confirm adding the param - --hook-config=--use-standard-markers=true fixes the issue.

@MaxymVlasov
Copy link
Collaborator

@Shr3ps v1.93.0 should work without - --hook-config=--use-standard-markers=true

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

No branches or pull requests

3 participants