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

Create a Terraform mirror protocol datasource #21486

Open
braunsonm opened this issue Apr 13, 2023 · 7 comments
Open

Create a Terraform mirror protocol datasource #21486

braunsonm opened this issue Apr 13, 2023 · 7 comments
Labels
help wanted Help is needed or welcomed on this issue new datasource New datasource support priority-4-low Low priority, unlikely to be done unless it becomes important to more people type:feature Feature (new functionality)

Comments

@braunsonm
Copy link

braunsonm commented Apr 13, 2023

How are you running Renovate?

Self-hosted Renovate

If you're self-hosting Renovate, tell us what version of Renovate you run.

35.32.2

If you're self-hosting Renovate, select which platform you are using.

Bitbucket Server

Was this something which used to work for you, and then stopped?

I am trying to get this working for the first time

Describe the bug

The logic for the Terraform Module and Provider datasource is flawed in that it uses the service discovery API that is only available on the official Terraform registries. This API is not to be used with custom registries. The documentation states this on Hashicorp here

The Provider Network Mirror protocol does not use the service discovery indirection, because a network mirror location is only a physical location and is never used as part of the identifier of a dependency in a Terraform configuration.

There are two problems with the logic in the datasource:

  • First, the equality check to see if the registry is hashicorp and therefore has the extended API, does not account for configuration that might change the default registry URLs
  • The service discovery API is still called even if the result is not required

See the logic here: https://github.com/renovatebot/renovate/blob/main/lib/modules/datasource/terraform-provider/index.ts#L65-L81

Given this configuration of renovate:

{
  "packageRules": [
    "matchDatasources": [
       "terraform-provider"
    ],
    "defaultRegistryUrls": [
      "https://mycustommirror.com"
    ]
  ]
}

First, the equality check in the lines I mentioned, just check the position of the registry URL in the list, instead of actually checking the contents are hashicorp. Second, service discovery is still called even if it is not required because queryRegistryExtendedApi should not be called.

The specific problem is here:

    const serviceDiscovery = await this.getTerraformServiceDiscoveryResult(
      registryUrl
    );

which is being called regardless of the registryUrl. This should only be called if the registry URL is from hashicorp, not from mirrors.

Custom solutions like Artifactory that implement the Terraform specification, rightly do not provide a .well-known/terraform.json, so any hosted registry will not work.

Relevant debug logs

Logs
{"name":"renovate","hostname":"renovate-hn7-mzgtc","msg":"GET https://myregistry.com/.well-known/terraform.json = (code=ERR_NON_2XX_3XX_RESPONSE, statusCode=404 retryCount=0, duration=16)"}

Have you created a minimal reproduction repository?

I have linked to a minimal reproduction in the description above

@braunsonm braunsonm added priority-5-triage status:requirements Full requirements are not yet known, so implementation should not be started type:bug Bug fix of existing functionality labels Apr 13, 2023
@braunsonm braunsonm changed the title Terraform Provider and Module does not follow the registry specification, mirrors and custom registries will not work Terraform Provider and Module does not follow the registry specification, registry mirrors will not work Apr 13, 2023
@viceice viceice added priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others datasource:terraform-module datasource:terraform-provider status:ready and removed status:requirements Full requirements are not yet known, so implementation should not be started priority-5-triage labels Apr 13, 2023
@secustor
Copy link
Collaborator

Both the provider and module registry protocols require a service discovery endpoint. If Artifactory do not exposes these, they are not following the protocol.

The network mirror protocol is simply currently not supported as datasource.

Regarding the defaultRegistryURL positions are referring to the readonly definition, so the order does not have an effect in your case.

Further I can see no linked reproduction repo.

@secustor secustor added status:waiting-on-response type:feature Feature (new functionality) auto:reproduction A minimal reproduction is necessary to proceed and removed type:bug Bug fix of existing functionality status:ready labels Apr 16, 2023
@github-actions
Copy link
Contributor

Hi there,

Get your issue fixed faster by creating a minimal reproduction. This means a repository dedicated to reproducing this issue with the minimal dependencies and config possible.

Before we start working on your issue we need to know exactly what's causing the current behavior. A minimal reproduction helps us with this.

To get started, please read our guide on creating a minimal reproduction.

We may close the issue if you, or someone else, haven't created a minimal reproduction within two weeks. If you need more time, or are stuck, please ask for help or more time in a comment.

Good luck,

The Renovate team

@braunsonm
Copy link
Author

The network mirror protocol is simply currently not supported as datasource.

Any plans to change this? This means that these modules cannot be used in firewalled corporate environments.

Further I can see no linked reproduction repo

I don't really think a reproduction repo is required. I provided the configuration to reproduce the problem, I can't really provide you with a mirror that has the problem.

@secustor
Copy link
Collaborator

secustor commented Apr 16, 2023

Currently there is no plan to implement this. The mirror protocol also only works for providers and not modules.

This means that these modules cannot be used in firewalled corporate environments.

This is only the case if you use Artifactory and at the same time use custom providers which are published there.

I don't really think a reproduction repo is required. I provided the configuration to reproduce the problem, I can't really provide you with a mirror that has the problem.

I need to know what the Terraform code you try to implement looks like.

@braunsonm
Copy link
Author

Sample here: https://github.com/braunsonm/renovate-terraform-providers-bug
Added with a intentionally out of date version of the provider. Like I said you will need to change the renovate.json though with your mirror.

@secustor
Copy link
Collaborator

Your Terraform code does not use a network mirror.

@braunsonm
Copy link
Author

Terraform code should not contain any registry mirror configuration. That is done on your local machine via a .terraformrc file.

The repo gives you a minimal reproduction sample where renovate is configured to use a mirror. If that mirror implements the provider mirror protocol, renovate will not work.

@secustor secustor added new datasource New datasource support help wanted Help is needed or welcomed on this issue priority-4-low Low priority, unlikely to be done unless it becomes important to more people status:ready and removed priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others status:waiting-on-response datasource:terraform-module datasource:terraform-provider labels Apr 21, 2023
@secustor secustor changed the title Terraform Provider and Module does not follow the registry specification, registry mirrors will not work Create a Terraform mirror protocol datasource Apr 21, 2023
@secustor secustor added reproduction:provided and removed auto:reproduction A minimal reproduction is necessary to proceed labels Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Help is needed or welcomed on this issue new datasource New datasource support priority-4-low Low priority, unlikely to be done unless it becomes important to more people type:feature Feature (new functionality)
Projects
None yet
Development

No branches or pull requests

4 participants