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

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

Open
kinseii opened this issue Sep 24, 2024 · 15 comments
Labels
area/local_installation bug Something isn't working

Comments

@kinseii
Copy link

kinseii commented Sep 24, 2024

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 kinseii added area/local_installation bug Something isn't working labels Sep 24, 2024
@MaxymVlasov
Copy link
Collaborator

@MaxymVlasov MaxymVlasov closed this as not planned Won't fix, can't repro, duplicate, stale Sep 24, 2024
@kinseii
Copy link
Author

kinseii commented Sep 24, 2024

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
Copy link
Author

kinseii commented Sep 24, 2024

@MaxymVlasov

@MaxymVlasov
Copy link
Collaborator

MaxymVlasov commented Sep 24, 2024

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 MaxymVlasov reopened this Sep 24, 2024
@MaxymVlasov MaxymVlasov added bug_with_workaround Something isn't working but there is a workaround and removed bug Something isn't working labels Sep 24, 2024
@kinseii
Copy link
Author

kinseii commented Sep 24, 2024

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

@kinseii
Copy link
Author

kinseii commented Sep 24, 2024

No error output was given with this line.

@kinseii
Copy link
Author

kinseii commented Sep 24, 2024

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
Copy link

velkovb commented Oct 1, 2024

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

@davidaparicio
Copy link

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
Copy link
Collaborator

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
Copy link

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
Copy link

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

@sonnysideup
Copy link

Samesies

@jseiser
Copy link

jseiser commented Oct 23, 2024

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

@MaxymVlasov MaxymVlasov added bug Something isn't working and removed bug_with_workaround Something isn't working but there is a workaround labels Nov 8, 2024
@MaxymVlasov
Copy link
Collaborator

MaxymVlasov commented Nov 8, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/local_installation bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants