pre-commit-terraform icon indicating copy to clipboard operation
pre-commit-terraform copied to clipboard

The `terraform-docs` hook no longer generated since the pre-commit-terraform v1.95.0

Open kinseii opened this issue 1 year ago β€’ 12 comments

The version description says that terraform-doc versions less than v0.12 are no longer supported. However, I have terraform-docs v0.19 in $PATH and README.md is not generated. If I revert pre-commit-terraform to v1.94.3 everything works.

.pre-commit-config.yaml:

repos:
  - repo: https://github.com/antonbabenko/pre-commit-terraform
    rev: v1.95.0
    hooks:
      - id: terraform_docs
        args:
          - --hook-config=--path-to-file=README.md
          - --hook-config=--add-to-existing-file=true
          - --hook-config=--create-file-if-not-exist=true
          - --hook-config=--use-standard-markers=true
          - --args=--config=.terraform-docs.yml

.terraform-docs.yml:

---
formatter: markdown table
output:
  file: README.md
  mode: inject

sort:
  enabled: true
  by: required

settings:
  anchor: true
  color: true
  default: true
  description: false
  escape: true
  hide-empty: false
  html: true
  indent: 2
  lockfile: true
  read-comments: true
  required: true
  sensitive: true
  type: true

Environment information

  • OS: Win11 with Ubuntu 24.04 on WSL2
Linux 5.15.146.1-microsoft-standard-WSL2 #1 SMP Thu Jan 11 04:09:03 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Description: Ubuntu 22.04.3 LTS
  • Tools availability and versions:
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
pre-commit 3.6.2
bash: line 3: tofu: command not found
Terraform v1.5.3
python SKIPPED
Python 3.10.12
checkov SKIPPED
infracost SKIPPED
terraform-docs version v0.19.0 linux/amd64
terragrunt version v0.54.15
terrascan SKIPPED
TFLint version 0.53.0
+ ruleset.terraform (0.9.1-bundled)
tfsec SKIPPED
trivy SKIPPED
tfupdate SKIPPED
hcledit SKIPPED

kinseii avatar Sep 24 '24 02:09 kinseii

Issue was already fixed in 1.96.1 https://github.com/antonbabenko/pre-commit-terraform/releases/tag/v1.96.1

MaxymVlasov avatar Sep 24 '24 09:09 MaxymVlasov

Issue was already fixed in 1.96.1 https://github.com/antonbabenko/pre-commit-terraform/releases/tag/v1.96.1

This problem persists on v1.96.1 as well. Please reopen.

kinseii avatar Sep 24 '24 09:09 kinseii

@MaxymVlasov

kinseii avatar Sep 24 '24 09:09 kinseii

Interesting, looks like there is an issue with --hook-config=--path-to-file=README.md which is obsolete when it provided by terraform-docs.yaml, but it shouldn't silently fail for sure.

Try

repos:
  - repo: https://github.com/antonbabenko/pre-commit-terraform
    rev: v1.96.1
    hooks:
      - id: terraform_docs
        args:
          # - --hook-config=--path-to-file=README.md
          - --hook-config=--add-to-existing-file=true
          - --hook-config=--create-file-if-not-exist=true
          - --hook-config=--use-standard-markers=true
          - --args=--config=.terraform-docs.yml

Also, compact version will looks like

repos:
  - repo: https://github.com/antonbabenko/pre-commit-terraform
    rev: v1.96.1
    hooks:
      - id: terraform_docs
        args:
          - --hook-config=--add-to-existing-file=true
          - --hook-config=--create-file-if-not-exist=true
          - --args=--config=.terraform-docs.yml

MaxymVlasov avatar Sep 24 '24 10:09 MaxymVlasov

@MaxymVlasov Yes, with the line - --hook-config=--path-to-file=README.md removed, everything worked!

kinseii avatar Sep 24 '24 10:09 kinseii

No error output was given with this line.

kinseii avatar Sep 24 '24 10:09 kinseii

So, I can confirm that removing the line with - --hook-config=--path-to-file=README.md helped and README.md started generating. With this line, the generation did not start and no errors were displayed.

I will not close the Issue, as I can see that obviously work will be done on it. Thank you so much for your help!

kinseii avatar Sep 24 '24 10:09 kinseii

For me it doesn't work even without the - --hook-config=--path-to-file=README.md. Reverting to v1.94.3 works though.

velkovb avatar Oct 01 '24 20:10 velkovb

Doesn't work where also :(

❯ pre-commit clean
Cleaned /Users/u/.cache/pre-commit.

❯ pre-commit uninstall
pre-commit uninstalled

❯ pre-commit run --all-files
[INFO] Initializing environment for https://github.com/astral-sh/ruff-pre-commit.
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Initializing environment for https://github.com/antonbabenko/pre-commit-terraform.
[ERROR] `terraform-docs` is not present in repository https://github.com/antonbabenko/pre-commit-terraform.  Typo? Perhaps it is introduced in a newer version?  Often `pre-commit autoupdate` fixes this.

❯ pre-commit autoupdate
[https://github.com/astral-sh/ruff-pre-commit] already up to date!
[https://github.com/pre-commit/pre-commit-hooks] already up to date!
[https://github.com/antonbabenko/pre-commit-terraform] Cannot update because the update target is missing these hooks: terraform-docs
[https://github.com/PyCQA/bandit] already up to date!

davidaparicio avatar Oct 06 '24 21:10 davidaparicio

Doesn't work where also :(

❯ pre-commit clean
Cleaned /Users/u/.cache/pre-commit.

❯ pre-commit uninstall
pre-commit uninstalled

❯ pre-commit run --all-files
[INFO] Initializing environment for https://github.com/astral-sh/ruff-pre-commit.
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Initializing environment for https://github.com/antonbabenko/pre-commit-terraform.
[ERROR] `terraform-docs` is not present in repository https://github.com/antonbabenko/pre-commit-terraform.  Typo? Perhaps it is introduced in a newer version?  Often `pre-commit autoupdate` fixes this.

❯ pre-commit autoupdate
[https://github.com/astral-sh/ruff-pre-commit] already up to date!
[https://github.com/pre-commit/pre-commit-hooks] already up to date!
[https://github.com/antonbabenko/pre-commit-terraform] Cannot update because the update target is missing these hooks: terraform-docs
[https://github.com/PyCQA/bandit] already up to date!

@davidaparicio Your issue is unrelated. Please install dependencies: https://github.com/antonbabenko/pre-commit-terraform?tab=readme-ov-file#1-install-dependencies

yermulnik avatar Oct 06 '24 22:10 yermulnik

The workaround doesn't work for me either. I had to revert to v1.94.2.

The code: .pre-commit-config.yaml .terraform-docs.yml

acelebanski avatar Oct 09 '24 19:10 acelebanski

I can confirm that I had the same issue and reverting to v1.94.2 fixed it.

b-milescu avatar Oct 11 '24 22:10 b-milescu

Samesies

sonnysideup avatar Oct 22 '24 13:10 sonnysideup

Can we remove the bug with workaround label, since the workaround doesnt work for us either.

❯ cat .pre-commit-config.yaml                                                                                                                                                                                                                 
repos:                                                                                                                                                                                                                                        
  - repo: https://github.com/antonbabenko/pre-commit-terraform
    rev: v1.96.1
    hooks:
      - id: terraform_fmt
      - id: terraform_docs
        args:
          - --hook-config=--add-to-existing-file=true # Boolean. true or false
          - --hook-config=--create-file-if-not-exist=true # Boolean. true or false
      - id: terraform_tflint
        args:
          - --args=--config=__GIT_WORKING_DIR__/.tflint.hcl
          - --hook-config=--delegate-chdir
aws_helm_nats [ξ‚  poc][!⇑]is πŸ“¦ v0.0.0 [🐍 v3.11.2]
❯ ls -l
drwxrwxr-x justin justin 4.0 KB Fri Oct 18 11:49:30 2024 ο„• aws_helm_nats
.rw-rw-r-- justin justin 167 B  Thu Oct 17 09:25:26 2024 ο€– Pipfile
.rw-r--r-- justin justin 141 KB Fri Oct 18 11:50:48 2024 ο€£ Pipfile.lock
.rw-rw-r-- justin justin 870 B  Thu Oct 17 09:26:19 2024 ξ˜† pyproject.toml
❯ pipenv run pre-commit run -a
Terraform fmt............................................................Passed
Terraform docs...........................................................Passed
❯ ls -l 
drwxrwxr-x justin justin 4.0 KB Fri Oct 18 11:49:30 2024 ο„• aws_helm_nats
.rw-rw-r-- justin justin 167 B  Thu Oct 17 09:25:26 2024 ο€– Pipfile
.rw-r--r-- justin justin 141 KB Fri Oct 18 11:50:48 2024 ο€£ Pipfile.lock
.rw-rw-r-- justin justin 870 B  Thu Oct 17 09:26:19 2024 ξ˜† pyproject.toml
❯ terraform-docs version        
terraform-docs version v0.19.0 af31cc6 linux/amd64

One thing to note, is in all of repo's whether its a Terraform Module like this one, or our monorepo used for deployments, the .pre-commit would live in the root of the dir, and all of the terraform would exists in child dir's. That not too dissimilar to how these are handled though, https://github.com/terraform-aws-modules/terraform-aws-eks where it understands to create the read me for those child modules

If we revert to [v1.94.3](https://github.com/antonbabenko/pre-commit-terraform/releases/tag/v1.94.3) things flow again

jseiser avatar Oct 23 '24 18:10 jseiser

Confirm that new README.md not generated for 1.95.0 and 1.96.2 with

        id: terraform_docs
        args:
          - --hook-config=--add-to-existing-file=true
          - --hook-config=--create-file-if-not-exist=true  # <---- This one broken?
          - --args=--lockfile=false
          - --hook-config=--parallelism-ci-cpu-cores=4 # DinD, can't calculate CPU cores

v1.94.3 works.

MaxymVlasov avatar Nov 08 '24 13:11 MaxymVlasov

For

  - repo: https://github.com/antonbabenko/pre-commit-terraform
    rev: v1.96.2
    hooks:
      - id: terraform_docs
        args:

works as expected:

          - --hook-config=--add-to-existing-file=true

works as expected:

          - --hook-config=--create-file-if-not-exist=true

broken (--create-file-if-not-exist=true ignored):

          - --hook-config=--add-to-existing-file=true
          - --hook-config=--create-file-if-not-exist=true

MaxymVlasov avatar Dec 24 '24 12:12 MaxymVlasov

rev: 819893c726df778321faf4772ae429b186887a48

should fix it. Fill free to try it now or wait till #731 merge

MaxymVlasov avatar Dec 24 '24 13:12 MaxymVlasov

This issue has been resolved in version 1.96.3 :tada:

antonbabenko avatar Dec 24 '24 14:12 antonbabenko