-
Notifications
You must be signed in to change notification settings - Fork 47
feat: adds terraform-docs as a linter 📄 #946
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
Conversation
⏱️ 27m total CI duration on this PR
|
output: rewrite | ||
formatter: true | ||
run_from: ${target_directory} | ||
run: terraform-docs markdown --output-file=README.md . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One note here: This is my team and I's (and I would suspect many many others) most common usage when using terraform-docs
with terraform child + root modules. However, the tool is fairly configurable and can be run in a lot of different ways. I didn't see an obvious example of how make these run
commands configurable, so I figured I'd put up this lightly working version for review + ask for feedback from the trunk team.
Do ya'll have any other configurable plugins that I should check out for inspiration to make sure this doesn't need an immediate update from the 2nd person to use it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EliSchleifer any thoughts here or ship it and we can deal with any requests for configurability in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix up the name of the command. Otherwise looks good to go
linters/terraform-docs/plugin.yaml
Outdated
main_tool: terraform-docs | ||
description: Generate terraform + tofu module documentation | ||
commands: | ||
- name: terraform-docs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The command name should more map what the command does than the name of the tool. So in this case given the formatter nature I would set name to "format"
Hi @Gowiem! Thanks for putting up this PR! I did want to weigh in with some unfortunate shortcomings with this approach:
With that being said, there are a couple options here:
Let me know your thoughts, I'd like to do what I can to unblock your team |
@TylerJang27 thanks for the info! Great stuff to know. I just checked out running Pretty simple: # Rest of trunk.yaml
actions:
enabled:
- terraform-docs
- trunk-announce
- trunk-check-pre-push
- trunk-fmt-pre-commit
- trunk-upgrade-available
definitions:
- id: terraform-docs
triggers:
- git_hooks: [pre-push, pre-commit]
run: terraform-docs markdown --output-file=README.md . This does the trick and AFTER my commit, I see changes in I could see a path forward with that... but it seems less capable than a linter plugin from the examples I am looking at in actions/. As a result I'm wondering the following:
Can I bug you to expand on these guarantees so I can better understand option 1?
|
@Gowiem here's some more info:
Let me know what you think. I personally recommend that Trunk Actions route, although I recognize that this exposes some limitations of our meta-linter. |
@TylerJang27 gotcha gotcha. Thanks for digging into terraform-docs and trying to explain + make this work -- I really appreciate this help! I am not fully able to grok all the internals of the problem with the HTL or pre-commit linter issues, but I don't think I need to. You're basically saying "There be dragons, don't do that", which I do get. So I just played around with the following, which while I don't necessarily like... I believe it'll work. Here's the setup: # .trunk/trunk.yaml
# ...
actions:
enabled:
- no-readme-changes-check
- terraform-docs-check
- terraform-docs
- trunk-announce
- trunk-check-pre-push
- trunk-fmt-pre-commit
- trunk-upgrade-available
definitions:
# Check for any README.md changes that are either staged or unstaged. Don't allow a push if there are any changes.
# We run this check before terraform-docs-check because --output-check will succeed even if README.md is not checked in.
- id: no-readme-changes-check
triggers:
- git_hooks: [pre-push]
run: git status --porcelain | grep -qE '^(.M|M).*README\.md$' && echo "README.md changes found" && exit 1 || exit 0
# --output-check does not update README.md, it only passes judgement on the content of README.md (regardless of status in git)
- id: terraform-docs-check
triggers:
- git_hooks: [pre-push]
run: terraform-docs . --output-check
- id: terraform-docs
triggers:
- git_hooks: [pre-commit]
run: terraform-docs . # .terraform-docs.yml
formatter: markdown
recursive:
enabled: false
path: modules
include-main: true
output:
file: README.md
mode: inject
template: |-
<!-- BEGIN_TF_DOCS -->
{{ .Content }}
<!-- END_TF_DOCS --> I'm willing to try all that out by rolling this config out across a few of internal + client repos to see how all this works in practice. But this solution is definitely not ideal: it requires a good bit of copy / pasta and feels custom. My goal with this PR was to get my team's process down to simply adding another linter (an action is fine too) so we can ditch It's not immediately apparent to me if I could accomplish the intended workflow by creating an action plugin. It feels like I can't from looking at the limited examples -- would you agree? If not, mind pointing me in the right direction? And if you do agree, should we try to create some GH issues that will improve the capabilities of actions so that this sort of workflow could be accomplished? |
@TylerJang27 nevermind -- I took a 2nd look at the existing actions and it seems there is likely a path forward using custom logic like what the I'm going to retract my "It's not immediately apparent to me if I could accomplish the intended workflow by creating an action plugin". I'll give an action plugin a go and report back 👍 |
@Gowiem that action seems like your best bet. A couple other reasonable options:
|
Closing this PR in favor of #966. Will continue the terraform-docs functionality there. |
## Info * Adds terraform-docs as an action to support automatically generating + updating terraform module documentation for terraform projects. * Closes #681 * This is working well locally. * Adding terraform-docs support via this PR in favor of #946 * Question: Is there a way to ensure that trunk installs `terraform-docs`? I only see a [`tools` declaration for `commitizen`](https://github.com/trunk-io/plugins/blob/main/actions/commitizen/plugin.yaml#L13-L24) and I'm unsure if I can enforce that the user is using [tools/terraform-docs](https://github.com/trunk-io/plugins/tree/main/tools/terraform-docs). What am I missing there?
Info
terraform-docs
as a linter plugin to support automatically generating + updating terraform module documentation for terraform projects.