antonbabenko / pre-commit-terraform

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

`terraform_docs` starting from 1.94.0 ignores `--hook-config=--add-to-existing-file=false` (our default behavior) #715

Closed MaxymVlasov closed 2 months ago

MaxymVlasov commented 2 months ago

Describe the bug

terraform-docs --output-mode="inject" --output-file=README.md md .

which is exactly what we run by default https://github.com/antonbabenko/pre-commit-terraform/blob/91b5ba0c184ca6ef14cdca0b6d3266084dbba166/hooks/terraform_docs.sh#L279

by

repos:
  - repo: https://github.com/antonbabenko/pre-commit-terraform
    rev: v1.94.2 # issue introduced in 1.94.0
    hooks:
      - id: terraform_docs

always updates/add terraform-docs section, as long as file exist.

This break your --add-to-existing-file setting, which by default set to false

How can we reproduce it?

testdir=$(mktemp -d)
cd $testdir
touch main.tf README.md
echo "
repos:
  - repo: https://github.com/antonbabenko/pre-commit-terraform
    rev: v1.94.2 # issue introduced in 1.94.0
    hooks:
      - id: terraform_docs
" > .pre-commit-config.yaml
git init
git add -A
pre-commit run

Workaround

antonbabenko commented 2 months ago

This issue has been resolved in version 1.94.3 :tada: