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

Have a go run compatible workflow #13

Closed
remyleone opened this issue Dec 15, 2020 · 5 comments · Fixed by #259
Closed

Have a go run compatible workflow #13

remyleone opened this issue Dec 15, 2020 · 5 comments · Fixed by #259
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@remyleone
Copy link

Currently, if I try to run the main.go directly with go I get the following errors. Could you have defaults such as undefined commit and devel version?

$ go run ./cmd/tfplugindocs/main.go
# command-line-arguments
cmd/tfplugindocs/main.go:13:34: undefined: version
cmd/tfplugindocs/main.go:14:5: undefined: commit
cmd/tfplugindocs/main.go:15:32: undefined: commit
@paultyng
Copy link
Contributor

I think you just need to do go run ./cmd/tfplugindocs/ (without the main.go) so all the files in the package are included.

@remyleone
Copy link
Author

# sieben @ sieben-macbook in ~/workspace/upstream/terraform-plugin-docs on git:main o [20:57:14]
$ go run ./cmd/tfplugindocs
go: downloading github.com/russross/blackfriday v1.6.0
rendering website for provider "terraform-plugin-docs"
exporting schema from Terraform
compiling provider "terraform-plugin-docs"
2021/01/26 20:57:33 error executing "/usr/local/bin/go", [go build -o /var/folders/58/dpfvy5xj6q5b44ly5zhfjfnh0000gn/T/tfws145824667/plugins/registry.terraform.io/hashicorp/terraform-plugin-docs/0.0.1/darwin_amd64/terraform-provider-terraform-plugin-docs]
2021/01/26 20:57:33 no Go files in /Users/sieben/workspace/upstream/terraform-plugin-docs
Error executing command: unable to generate website: error executing "/usr/local/bin/go": exit status 1

exit status 1

@paultyng
Copy link
Contributor

It needs to run from the root working directory of a provider. Typically we do this using a go generate command, for example: https://github.com/hashicorp/terraform-provider-scaffolding/blob/bec212504f3fc7ad42e5f3a80425cb95872dda28/main.go#L18-L20

So if you wanted to test this from a provider, you would add this to your go.mod and use a replace directive to locate the files on disk. Does that make sense? I'll see if I can find an example of this, but it should at least be documented in this repo for folks to test/debug.

@bflad bflad added the enhancement New feature or request label Jun 6, 2023
@bflad bflad self-assigned this Jun 6, 2023
@bflad bflad added this to the v0.15.0 milestone Jun 6, 2023
bflad added a commit that referenced this issue Jun 6, 2023
Reference: #13

By default, the generator expects to be running in the root provider directory. The new `provider-dir` flag enables developers to run the command in any directory where the relative or absolute path is passed in as the base directory for all file operations for a provider codebase. All prior behaviors should be preserved, such as customizing via other flags like `examples-dir`.

Due to lack of existing end-to-end testing (known technical debt), verified by locally compiling and running against existing HashiCorp-owned provider implementations which use `tfplugindocs` and by running the command in a subdirectory of hashicorp/terraform-provider-tls which has a mixture of custom and default templates and observed no changes or errors:

```console
$ tfplugindocs generate -provider-dir=..
rendering website for provider "terraform-provider-tls" (as "terraform-provider-tls")
copying any existing content to tmp dir
exporting schema from Terraform
compiling provider "tls"
using Terraform CLI binary from PATH if available, otherwise downloading latest Terraform CLI binary
running terraform init
getting provider schema
rendering missing docs
generating missing resource content
resource "tls_locally_signed_cert" template exists, skipping
resource "tls_private_key" template exists, skipping
resource "tls_self_signed_cert" template exists, skipping
resource "tls_cert_request" template exists, skipping
generating missing data source content
resource "tls_certificate" template exists, skipping
generating template for "tls_public_key"
generating missing provider content
provider "terraform-provider-tls" template exists, skipping
rendering static website
cleaning rendered website dir
rendering templated website to static markdown
rendering "data-sources/certificate.md.tmpl"
rendering "data-sources/public_key.md.tmpl"
rendering "index.md.tmpl"
rendering "resources/cert_request.md.tmpl"
rendering "resources/locally_signed_cert.md.tmpl"
rendering "resources/private_key.md.tmpl"
rendering "resources/self_signed_cert.md.tmpl"
```
@bflad bflad closed this as completed in #259 Jun 7, 2023
bflad added a commit that referenced this issue Jun 7, 2023
Reference: #13

By default, the generator expects to be running in the root provider directory. The new `provider-dir` flag enables developers to run the command in any directory where the relative or absolute path is passed in as the base directory for all file operations for a provider codebase. All prior behaviors should be preserved, such as customizing via other flags like `examples-dir`.

Due to lack of existing end-to-end testing (known technical debt), verified by locally compiling and running against existing HashiCorp-owned provider implementations which use `tfplugindocs` and by running the command in a subdirectory of hashicorp/terraform-provider-tls which has a mixture of custom and default templates and observed no changes or errors:

```console
$ tfplugindocs generate -provider-dir=..
rendering website for provider "terraform-provider-tls" (as "terraform-provider-tls")
copying any existing content to tmp dir
exporting schema from Terraform
compiling provider "tls"
using Terraform CLI binary from PATH if available, otherwise downloading latest Terraform CLI binary
running terraform init
getting provider schema
rendering missing docs
generating missing resource content
resource "tls_locally_signed_cert" template exists, skipping
resource "tls_private_key" template exists, skipping
resource "tls_self_signed_cert" template exists, skipping
resource "tls_cert_request" template exists, skipping
generating missing data source content
resource "tls_certificate" template exists, skipping
generating template for "tls_public_key"
generating missing provider content
provider "terraform-provider-tls" template exists, skipping
rendering static website
cleaning rendered website dir
rendering templated website to static markdown
rendering "data-sources/certificate.md.tmpl"
rendering "data-sources/public_key.md.tmpl"
rendering "index.md.tmpl"
rendering "resources/cert_request.md.tmpl"
rendering "resources/locally_signed_cert.md.tmpl"
rendering "resources/private_key.md.tmpl"
rendering "resources/self_signed_cert.md.tmpl"
```
@bflad
Copy link
Member

bflad commented Jun 7, 2023

As noted above, the expected way to run the tfplugindocs command is in the root directory of the provider codebase, however v0.15.0 about to be released adds a new generate -provider-dir flag which can be used to point the command at another directory other than the current working directory.

Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants