Skip to content

Add new hook for running terraform-docs which will replace content of README.md (using Python)#27

Merged
antonbabenko merged 5 commits intoantonbabenko:masterfrom
RothAndrew:feature/new_hook
Dec 14, 2018
Merged

Add new hook for running terraform-docs which will replace content of README.md (using Python)#27
antonbabenko merged 5 commits intoantonbabenko:masterfrom
RothAndrew:feature/new_hook

Conversation

@RothAndrew
Copy link
Contributor

@RothAndrew RothAndrew commented Dec 14, 2018

Adds a new hook called terraform_docs_replace which uses the documentation found at the top of main.tf to recreate README.md. I'm open to suggestions on the name, I don't love it.

Fix #17

I know this is going to probably come across as "going against the grain" a little bit, but I wanted to write it because this is how I've done all my Terraform documentation, and this seemed like the right place for it to live.

It's not super thoroughly tested, but from the testing that I have done it looks very promising. Switching to Python instead of a shell script actually gives better OS compatibility because it works anywhere Python works vs the bash scripts that only work on OS's in the Unix family. Also, we know Python is already installed because you need Python to run pre-commit

Copy link
Owner

@antonbabenko antonbabenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. It looks pretty good, but I propose to make few customization to make it more flexible:

  1. Make filename README.md customizable via args.
  2. Where main.tf comes from? Where it is used? Why main.tf?
  3. Move setup.py and package files inside a folder (eg, terraform_docs_replace) to not mix root of the repo.
  4. sed command can be different between systems. Since this is already in Python I would recommend to use native Python methods and replace sed.

@RothAndrew
Copy link
Contributor Author

RothAndrew commented Dec 14, 2018

Make filename README.md customizable via args.

Sure that sounds reasonable.

Where main.tf comes from? Where it is used? Why main.tf?

main.tf is the standard entrypoint for a Terraform module. terraform-docs looks for documentation at the top of main.tf to add to the markdown document it creates. I'm not explicitly telling it to do that.

Move setup.py and package files inside a folder (eg, terraform_docs_replace) to not mix root of the repo.

According to the docs setup.py has to stay at the root in order to get picked up by pip. Note: a single setup.py file will support any and all future pre-commit hooks written in Python. All you have to do is add a line to the console_scripts array in entry_points.

sed command can be different between systems. Since this is already in Python I would recommend to use native Python methods and replace sed.

Makes sense

@RothAndrew RothAndrew changed the title Add new hook for running terraform-docs with main.tf doc replace WIP: Add new hook for running terraform-docs with main.tf doc replace Dec 14, 2018
@antonbabenko
Copy link
Owner

Looks good. :)

Could you also add a note to README for developers (not users) something like "It is possible to support any and all future pre-commit hooks written in Python. All you have to do is add a line to the console_scripts array in entry_points."

@RothAndrew
Copy link
Contributor Author

Don't merge this yet. I'm not done with it.

@RothAndrew
Copy link
Contributor Author

Actually, maybe I am. @antonbabenko if you're fine with leaving the call to sed in for now this can be merged. I'll open another PR to change the sed call to native Python.

@RothAndrew
Copy link
Contributor Author

Ready to merge. I'm done making changes unless there are more requested.

@antonbabenko antonbabenko changed the title WIP: Add new hook for running terraform-docs with main.tf doc replace Add new hook for running terraform-docs which will replace content of README.md (using Python) Dec 14, 2018
@antonbabenko antonbabenko merged commit a52b507 into antonbabenko:master Dec 14, 2018
@antonbabenko
Copy link
Owner

Great! v1.8.0 has been released.

Thanks @RothAndrew for the work!

@RothAndrew RothAndrew deleted the feature/new_hook branch December 14, 2018 21:32
@robinbowes
Copy link
Contributor

main.tf is the standard entrypoint for a Terraform module. terraform-docs looks for documentation at the top of main.tf to add to the markdown document it creates. I'm not explicitly telling it to do that.

This is not clear - could you update the docs to explain this, @RothAndrew ?

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

Successfully merging this pull request may close these issues.

3 participants