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

Use terraform-docs native saving to file #179

Open
khos2ow opened this issue Mar 9, 2021 · 7 comments
Open

Use terraform-docs native saving to file #179

khos2ow opened this issue Mar 9, 2021 · 7 comments
Labels
estimate/2days Need 2 work days to be done feature New feature or request hook/terraform_docs Bash hook

Comments

@khos2ow
Copy link
Contributor

khos2ow commented Mar 9, 2021

In terraform-docs v0.12.0, we've added ability to insert generated output directly into a target file (terraform-docs/terraform-docs#286)! This can replace all the sed/awk/perl and drastically simplify the process to the point of only executing:

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

Check out all the available option to configure this.

We've just cut a v0.12.0-beta.1 for folks to start experimenting. Please feel free to start using and file any issues or feedback.

@antonbabenko
Copy link
Owner

Thanks a lot for the update!

That would be really nice if we can remove sed/awk/perl hack which was there since pre-0.12 times :)

I don't have time for this work myself but maybe someone from the community can make a PR.

@antonbabenko antonbabenko pinned this issue Mar 10, 2021
@antonbabenko antonbabenko added the help wanted Extra attention is needed label Mar 10, 2021
@jonmaestas
Copy link

Does it make sense to deprecate terraform_docs_without_aggregate_type_defaults and terraform_docs_replace?

Why not just support native terraform-docs usage similar to how tflint is setup? It seems like the other terraform_docs_* options were there because of the lack of features out-of-the-box with terraform-docs at the time, and that's no longer the case.

@MaxymVlasov MaxymVlasov added estimate/2days Need 2 work days to be done hook/terraform_docs Bash hook feature New feature or request and removed help wanted Extra attention is needed labels Sep 9, 2021
@github-actions
Copy link

This issue has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this issue will be closed in 10 days

@github-actions github-actions bot added the stale Denotes an issue or PR has remained open with no activity and has become stale. label Oct 10, 2021
@MaxymVlasov MaxymVlasov removed the stale Denotes an issue or PR has remained open with no activity and has become stale. label Oct 14, 2021
@kevcube
Copy link

kevcube commented Feb 22, 2023

This fix would be very helpful to me! 😸

@dzavalkin-scayle
Copy link

Any chance to get this fixed and remove all those crazy dependencies like perl?
terraform-docs is already at version 16 (for a long time btw) and with correct .terraform-docs.yml I'm ending up with my README.md corrupted by the hook:

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
README.md updated successfully
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

While when I run terraform-docs from cli README.md is updated as expected.
Basically, terraform-docs is currently unusable if we want to preserve possibility to run terraform-docs manually from CLI...

Just for the reference, my .terraform-docs.yml looks like this:

formatter: "markdown table"
output:
  file: README.md
  mode: inject
  template: |-
    <!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
    {{ .Content }}
    <!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

Would be also great to get rid of custom <!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> and <!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> markers and use default <!-- BEGIN_TF_DOCS --> and <!-- END_TF_DOCS -->...

@MaxymVlasov
Copy link
Collaborator

Feel free to implement it and send PR, your help will be much appreciated.

@gchappel
Copy link
Contributor

gchappel commented Sep 14, 2023

Any chance to get this fixed and remove all those crazy dependencies like perl? terraform-docs is already at version 16 (for a long time btw) and with correct .terraform-docs.yml I'm ending up with my README.md corrupted by the hook:

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
README.md updated successfully
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

While when I run terraform-docs from cli README.md is updated as expected. Basically, terraform-docs is currently unusable if we want to preserve possibility to run terraform-docs manually from CLI...

Just for the reference, my .terraform-docs.yml looks like this:

formatter: "markdown table"
output:
  file: README.md
  mode: inject
  template: |-
    <!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
    {{ .Content }}
    <!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

Would be also great to get rid of custom <!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> and <!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK --> markers and use default <!-- BEGIN_TF_DOCS --> and <!-- END_TF_DOCS -->...

@dzavalkin-scayle I'm coming across this behaviour too - there's some kind of conflict between terraform-docs which now writes to the README.md natively instead of printing the rendered text to stdout and the current pre-commit hook which takes stdout and does its own replacement into the README.md

I've worked around this by adding an argument into my hook which restores the previous behaviour of making terraform-docs return the parsed output on stdout

        args:
          - --args=--output-file=""

Maybe this helps you too? In the long term I agree that the entire wrapper should just be simplified and require a recent version of terraform-docs to do this natively; but I don't have time for that at the moment so this was a quick band-aid for me.

edit: this may not work with older hooks, I had a repo using 1.71.0 of this repo which created a bunch of files called "". I upgraded to 1.76.0 to match some of my other repos, and this hook works OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
estimate/2days Need 2 work days to be done feature New feature or request hook/terraform_docs Bash hook
Projects
None yet
Development

No branches or pull requests

7 participants