Description
What problem are you facing?
Presently, the registry URL is hard-coded to registry.terraform.io
.
With the advent of OpenTofu, more registries have popped up, including better support for internal/enterprise/corporate "private" registries. A user of this tool should be able to specify the preferred URL pattern to use for the registry.
How could terraform-docs help solve your problem?
The three most popular public registries (as of today's date) have the following URL patterns (arbitrarily picking version v5.65.0
).
- https://registry.terraform.io/providers/hashicorp/aws/5.65.0/docs
- https://search.opentofu.org/provider/hashicorp/aws/v5.65.0
- https://library.tf/providers/hashicorp/aws/5.65.0
I propose that as a CLI flag and config file entry, a user should be able to provide a keyword to signify one of the popular public registries, or a Go-template URL pattern for a custom/private registry.
As an example, let's look at settings. We could add a new entry called registry-url
, which would accept a string.
settings:
anchor: true
color: true
default: true
registry-url: ''
...
Reviewing When not to use Plain Scalars to understand which characters can be used at the beginning of a string value, unquoted, it looks like :<space>
is unavailable, but :<nospace>
should be valid.
We could use certain "short" strings as placeholders for well-known values, then fall back to Go-template values for custom URLs.
:terraform:
:opentofu:
:library-tf:
https://registry.company.com/internal-registry/{{.Namespace}}/{{.Provider}}/{{.ProviderVersion}}/docs
The last of these would likely need to be quoted, which is reasonable.
settings:
default: true
registry-url: :library-tf: # I *think* this is valid. Untested. Can still be quoted.
...
settings:
default: true
registry-url: 'https://registry.company.com/internal-registry/{{.Namespace}}/{{.Provider}}/{{.ProviderVersion}}/docs'
...
Or if you'd prefer to simply require a quoted value, maybe a different meta-character would be preferred over :
for readability. Perhaps @
?
settings:
default: true
registry-url: '@opentofu'
...
Just some ideas.
Related improvements
If a provider has a version constraint (e.g., ~> 4.60
), then instead of always linking to the latest
version, we should honor the version constraint when we create the registry links. Continuing to use hashicorp/aws
as an example, the most appropriate version for the ~> 4.60
constraint is 4.67.0
.
In my proposal above, where I mentioned .ProviderVersion
as a Go-template variable, that variable would be set to 4.67.0
instead of latest
.
Why? Many corporations have large numbers of apps in various states of maintenance, and may be using an older version of Terraform or Terraform Module or Terraform Provider until they have a chance to update. My previous company has in-use versions of Terraform 0.7 that just never got updated. Being able to provide accurate documentation for well-crafted projects should be possible, and always linking to latest
is inaccurate.