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

Missing registry API endpoint for Get Provider #1337

Open
guineveresaenger opened this issue Nov 27, 2024 · 5 comments
Open

Missing registry API endpoint for Get Provider #1337

guineveresaenger opened this issue Nov 27, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@guineveresaenger
Copy link

guineveresaenger commented Nov 27, 2024

Thank you for reporting an issue.

I can query a provider's information in the Terraform registry like so:

curl -i https://registry.terraform.io/v1/providers/hashicorp/random/3.6.3

which allows me to see metadata about the provider source.

When I do the same for OpenTofu, I get a 404:

curl -i https://registry.opentofu.org/v1/providers/hashicorp/random/3.6.3

It is entirely possible that this is an enhancement request rather than a bug, and the HashiCorp-owned registry is somewhat cagey around the providers service endpoints - but this is how I'd expect the registry protocol to behave.

Context here is I'd like to obtain the sourcecode repo via metadata rather than via assumed naming convention.

OpenTofu Version

n/a

OpenTofu Configuration Files

n/a

@guineveresaenger guineveresaenger added the bug Something isn't working label Nov 27, 2024
@abstractionfactory
Copy link
Contributor

abstractionfactory commented Nov 27, 2024

Hi @guineveresaenger we are implementing the documented provider registry protocol we inherited from HashiCorp, which does not expose an endpoint at this address. If you know which os and architecture you are looking for, you can use the https://registry.opentofu.org/v1/providers/hashicorp/random/3.6.3/download/linux/amd64 endpoint. Alternatively, you can clone the registry repository and access the data directly.

Could you elaborate on your use case for this endpoint? (Unfortunately, I cannot access the Terraform registry to check their data structure as this would violate their Terms of Service, so you'll have to describe what exactly you are looking for.)

@abstractionfactory abstractionfactory added enhancement New feature or request and removed bug Something isn't working labels Nov 27, 2024
@guineveresaenger
Copy link
Author

Hi @abstractionfactory - thanks for the quick reply! 💟

I'm a little confused, as this endpoint is clearly accessible and public from the Terraform registry. You're right, though; this endpoint isn't documented in the registry protocol, so I figured it was an oversight.
I would expect both registry hosts to exhibit similar behavior, but of course if the spec isn't there, it's hard to implement.

My use case is this:

I would like to determine the source code location (i.e. githost/org/terraform-provider-foo) programmatically via the provider's registry endpoint, knowing a provider's OpenTofu name and version. I can infer it currently, assuming that the git host is always github.com and the org and module name always map to the namespace and type. But that's an assumption based on current most common (?) practice.

When I run

curl -i https://registry.terraform.io/v1/providers/hashicorp/random/3.6.3

I get back a 200 response, headers, and the following payload:

{
  "id": "hashicorp/random/3.6.3",
  "owner": "hashicorp",
  "namespace": "hashicorp",
  "name": "random",
  "alias": "random",
  "version": "3.6.3",
  "tag": "v3.6.3",
  "description": "terraform-provider-random",
  "source": "https://github.com/hashicorp/terraform-provider-random", 
  "published_at": "2024-09-11T14:08:43Z",
  "downloads": 1310537974,
  "tier": "official",
  "logo_url": "/images/providers/hashicorp.svg",
  "versions": [...]
  ...
  }

It's the source field I'm after.

Alternatively, you can clone the registry repository and access the data directly.

Unfortunately that won't generalize to all Terraform registries. 😅 but thank you for pointing it out.

@abstractionfactory
Copy link
Contributor

This endpoint isn't documented indeed, which makes it unlikely that other registries will support it.

I don't see any problems generating this response, or we can add it to the new api.opentofu.org endpoint (still in beta).

I'll talk to my fellow core team members and we'll try to make a decision on this fairly quickly.

@guineveresaenger
Copy link
Author

That's a fair point about other registries. I should file an issue against the registry protocol to at least get clarification here.

Thank you so much for considering! ❤️

@abstractionfactory
Copy link
Contributor

abstractionfactory commented Dec 2, 2024

@guineveresaenger I just did a quick check and the OpenTofu API may contain the information you seek:

https://api.opentofu.org/registry/docs/providers/opentofu/aws/v5.78.0/index.json (See the link field.)

You can find the API description at https://api.opentofu.org

guineveresaenger added a commit to pulumi/pulumi-terraform-bridge that referenced this issue Dec 10, 2024
This pull request adds logic that enables us to generate resource docs
for a dynamically bridged provider using the upstream dependency.

Usage for remote providers:
`pulumi package get-schema terraform-provider <registry address>
<version> fullDocs=<true|false>`.

Adds a parameterized arg field to `pulumi package get-schema
terraform-provider <registry address> <version>` called `fullDocs`,
which when set to `true` will instruct the bridge to `git clone --depth
1 -b <version> <terraform provider github repo> <local dir for dynamic
docs>`. This allows us to keep the exact same docs logic we have
established. The shallow clone targets the exact doc version we need.
(*)

For this, we infer the github repo from the OpenTofu org name. It is
based on the assumption that `registry.opentofu.org/org/foo` is based on
a provider that lives at `github.com/org/terraform-provider-foo`.
OpenTofu says their protocol follows that of the HashiCorp Terraform
Registry which [requires an org/user and a provider name of the format
`terraform-provider-foo`](https://developer.hashicorp.com/terraform/registry/providers/publishing)
and we have historical evidence that GitHub is the most commonly used
source host for terraform providers. See also
opentofu/registry#1337.

Usage for local providers:
`pulumi package get-schema terraform-provider <local-path>
upstreamRepoPath=<localPath>`. Here, the local docs path gets read
directly into `upstreamRepoPath`.

The one thing that is perhaps missing here is to expand the remote args
to allow to take a source repo as an additional argument. However, our
internal use case is primarily one of automation, so this is not an
immediate need.

(*)Cloning docs for the AWS terraform provider at v5.70.0 has the
following time performance:
```
git clone --depth 1 -b v5.70.0  awsDir  
2.06s user 
1.62s system 
34% cpu 
10.713 total
```

Fixes #2607
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants