-
Notifications
You must be signed in to change notification settings - Fork 9
misc: use tfplugindocs to generate docs. #498
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
2558e2f
to
4863f23
Compare
I really like this idea! I haven't used |
Rather than constructing docs manually and running them through a linter, use tfplugindocs to generate them. We move examples into the examples/ directory, and override default templates in the templates/ directory. We also add new make targets to generate docs and check that the generated docs match the code. Resolves #490.
e0c01b8
to
aed09cd
Compare
Conflicts resolved. @lgfa29, thanks for adding the missing descriptions to the resource definitions. @sudomateo, this is ready for a look when you have time. |
Ack! Adding it to my list for the day. Have a few back-to-back meetings but later in the afternoon I'll review. |
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.
Thank you both for working on this! This is much better than handwriting documentation. I made a quick change to solidify my understanding of how this is meant to work.
I'm not sold on the examples in a separate directory versus have resource specific templates but I understand the generator looks for a certain directory structure to generate resource and data source documentation from a default template. My motivation for this is when removing a resource the generated documentation is removed but the examples remain. This is something we can hone in on in the future though so not blocking at all.
My other curiosity is using Go's embed
to hold the resource or data source level MarkdownDescription
so it doesn't overwhelm the code. The attributes MarkdownDescription
is find since it's usually one line but the top-level MarkdownDescription
is often a few lines. Again, a future thing we can hone in on as we use this.
Thanks again!
Agreed that some of the assumptions the docs generator makes are silly, but also agreed that we can fix up the implications later on. Thanks for the review! |
One minor benefit of examples being in a separate folder is that they can become "executable" Terraform files. I usually have As for the One approach I considered was to store the string in a variable, but since all files are in the same package, the variable would need to be very specific, like: resourceFloatingIPDescription = `
...
`
// ...
func (f *floatingIPResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
MarkdownDescription: resourceFloatingIPDescription,
Attributes: map[string]schema.Attribute{
// ... I didn't feel strongly about either way, so I just added everything to the schema. But for resources or data sources with longer descriptions, it may be worth considering the variable approach. |
Agreed. That, plus syntax highlighting and formatting makes having external example files attractive.
This is something that always bothered me about Terraform providers. Having everything in the same package leads to use having to create long, unique names like |
It doesn't really have to be all in the same package, it's just easier to start like that 😅 We can have them in different pacakages and import the packages in terraform-provider-oxide/internal/provider/provider.go Lines 162 to 206 in a2279ca
The AWS provider, for example, groups them by service: |
Let's explore that! I'll add an agenda item to our next sync to discuss it further. |
Rather than constructing docs manually and running them through a linter, use tfplugindocs to generate them. We move examples into the examples/ directory, and override default templates in the templates/ directory. We also add new make targets to generate docs and check that the generated docs match the code.
Resolves #490.
Note: this is a low priority, but I wanted to fix the paper cut before investing more time in the provider.
Also note: the generated docs aren't identical to the current docs. I haven't gone through and tried to make them as similar as possible, but we can do more to minimize the diff if we want to.