antonbabenko / pre-commit-terraform

pre-commit git hooks to take care of Terraform configurations 🇺🇦
MIT License
3.19k stars 536 forks source link

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

Open kinseii opened 3 weeks ago

kinseii commented 3 weeks ago

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

MaxymVlasov commented 3 weeks ago

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

kinseii commented 3 weeks ago

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 commented 3 weeks ago

@MaxymVlasov

MaxymVlasov commented 3 weeks ago

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
kinseii commented 3 weeks ago

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

kinseii commented 3 weeks ago

No error output was given with this line.

kinseii commented 3 weeks ago

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!

velkovb commented 2 weeks ago

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

davidaparicio commented 1 week ago

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!
yermulnik commented 1 week ago

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

acelebanski commented 1 week ago

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

b-milescu commented 5 days ago

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