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 sed issue with v1.93.1 for mac default sed #707

Closed
BeneHa opened this issue Aug 30, 2024 · 6 comments · Fixed by #708
Closed

terraform_docs sed issue with v1.93.1 for mac default sed #707

BeneHa opened this issue Aug 30, 2024 · 6 comments · Fixed by #708

Comments

@BeneHa
Copy link

BeneHa commented Aug 30, 2024

Describe the bug

Since the fix of a bug in #704 by @cschroer , the empty sed -i flag does not work for me. Now, a README.md-e file is being created as well as the README.md. I am using Mac's default sed.

I know I can install GNU sed, but I think many users are using the default sed and will run into this issue.

How can we reproduce it?

Run pre-commit tf_docs on a Mac with the default sed installed.

Environment information

  • OS:
Darwin 2BY1-1GLP3 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000 arm64
  • sed:
sed_version="$(sw_vers -productVersion)"
echo $sed_version
14.6.1
  • Tools availability and versions:
GNU bash, version 5.2.32(1)-release (aarch64-apple-darwin23.4.0)
pre-commit 3.8.0
zsh: command not found: tofu
Terraform v1.9.5
python SKIPPED
Python 3.12.4
checkov SKIPPED
infracost SKIPPED
terraform-docs version v0.18.0 228c7a7 darwin/arm64
terragrunt SKIPPED
terrascan SKIPPED
TFLint version 0.53.0
+ ruleset.terraform (0.9.1-bundled)
tfsec SKIPPED
trivy SKIPPED
tfupdate SKIPPED
hcledit SKIPPED
  • .pre-commit-config.yaml:
file content
repos:
  - repo: https://github.com/antonbabenko/pre-commit-terraform.git
    rev: v1.94.0
    hooks:
      - id: terraform_docs
        args:
          - --hook-config=--create-file-if-not-exist=true
@BeneHa BeneHa added area/local_installation bug Something isn't working labels Aug 30, 2024
@drAlberT
Copy link

drAlberT commented Aug 30, 2024

I confirm the issue ... the sed command does not raise any error (of course) but creates a new file. @MaxymVlasov @yermulnik this is why I was saying that sed -i'' -e (without a space before the '') is not working on Mac in #704.

Screenshot 2024-08-30 at 10 46 40

@robinbowes
Copy link
Contributor

I can confirm this behaviour:

❯ ls
tt.txt

❯ gsed -i'' -e 's/foo/foobar/' tt.txt

❯ ls
tt.txt

❯ sed -i'' -e 's/foo/foobar/' tt.txt

❯ ls
tt.txt   tt.txt-e

Some useful information here about replacing strings in files: http://mywiki.wooledge.org/BashFAQ/021

tl;dr: "The preferred way to modify a file is to create a new file within the same file system, write the modified content into it, and then mv it to the original name."

@MaxymVlasov

This comment was marked as outdated.

@MaxymVlasov
Copy link
Collaborator

Test this please

repos:
  - repo: https://github.com/antonbabenko/pre-commit-terraform
    rev: a76f03bfc4978741f37f79a6b4a86dc72078a78d
    hooks:
      - id: terraform_docs

@drAlberT
Copy link

drAlberT commented Aug 30, 2024

Test this please

repos:
  - repo: https://github.com/antonbabenko/pre-commit-terraform
    rev: a76f03bfc4978741f37f79a6b4a86dc72078a78d
    hooks:
      - id: terraform_docs

Yes, it works

@antonbabenko
Copy link
Owner

This issue has been resolved in version 1.94.1 🎉

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