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 hook requires GNU sed #14

Closed
brainsik opened this issue May 18, 2018 · 4 comments
Closed

terraform_docs hook requires GNU sed #14

brainsik opened this issue May 18, 2018 · 4 comments

Comments

@brainsik
Copy link
Contributor

I kept getting this error when trying to use the terraform_docs hook:

Terraform Docs...........................................................Failed
hookid: terraform_docs

sed: 1: "/BEGINNING OF PRE-COMMI ...": unexpected EOF (pending }'s)

Further inspection revealed this is a limitation of the BSD sed shipping with the latest macOS:

$ sed -i -n '/BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK/{p;:a;N;/END OF PRE-COMMIT-TERRAFORM DOCS HOOK/!ba;s/.*\n/I_WANT_TO_BE_REPLACED\n/};p' README.md
sed: 1: "/BEGINNING OF PRE-COMMI ...": unexpected EOF (pending }'s)

Running the same command using GNU sed (installed as gsed by Homebrew):

$ gsed -i -n '/BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK/{p;:a;N;/END OF PRE-COMMIT-TERRAFORM DOCS HOOK/!ba;s/.*\n/I_WANT_TO_BE_REPLACED\n/};p' README.md
$ cat README.md 
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
I_WANT_TO_BE_REPLACED
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
@antonbabenko
Copy link
Owner

First, thanks for opening this issue!

The question which I have been asking myself few times in several projects which version(s) of sed should I use. If I understand correctly GNU sed is more powerful and easily available for the most of operating systems (right?).

Will it be fine, if we just extend the script to print a statement that GNU sed should be installed? "pass" if GNU sed does not exist.

It may be possible to rewrite it using Python (or anything else), but there will be the similar issue - which version of Python to expect (python 2.7 vs 3.x?)

@brainsik
Copy link
Contributor Author

I ended up rewriting the sed commands in Perl, which should make the script more universally usable without external tools. See #15.

@varac
Copy link

varac commented Nov 30, 2020

Well, not excatly because it breaks setups in small docker images where perl is not installed (like the official hashicorp/terraform:0.13.5 docker image i.e.):

Terraform docs...........................................................Failed
- hook id: terraform_docs
- exit code: 127

/builds/project-0/.cache/pre-commit/repowvx2neb8/terraform_docs.sh: line 144: perl: command not found

@antonbabenko
Copy link
Owner

Make sure to install perl. I know it sounds odd in 2020 but we use it here also :)

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

No branches or pull requests

3 participants