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

Support source URLs for GitLab-provided terraform modules #25003

Closed
secustor opened this issue Oct 3, 2023 Discussed in #25002 · 1 comment · Fixed by #25008
Closed

Support source URLs for GitLab-provided terraform modules #25003

secustor opened this issue Oct 3, 2023 Discussed in #25002 · 1 comment · Fixed by #25008
Labels
datasource:terraform-module priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others status:in-progress Someone is working on implementation type:feature Feature (new functionality)

Comments

@secustor
Copy link
Collaborator

secustor commented Oct 3, 2023

Discussed in #25002

Originally posted by colinodell October 3, 2023
TL;DR: I would like Renovate's terraform-module datasource to always capture the source URL field if provided by the registry, as some registries (like GitLab's) do expose this non-standard field.

Details

The Terraform Module Registry Protocol defines a minimal specification that all implementations must follow. Notably, the "list available versions" endpoint must return responses like this:

{
   "modules": [
      {
         "versions": [
            {"version": "1.0.0"},
            {"version": "1.1.0"},
            {"version": "2.0.0"}
         ]
      }
   ]
}

However, implementations are allowed to provided a superset of the API:

The public Terraform Registry implements a superset of the API described on this page, in order to capture additional information used in the registry UI. For information on those extensions, see Terraform Registry HTTP API. Third-party registry implementations may choose to implement those extensions if desired, but Terraform CLI itself does not use them.

Both the public Terraform Registry and GitLab's Terraform Registry provide an additional source field which may (or may not) contain a valid URL.

Currently, Renovate will only check for and use that source field if the registry URL contains terraform.io:

if (this.extendedApiRegistryUrls.includes(registryUrlNormalized)) {
return await this.queryRegistryExtendedApi(
serviceDiscovery,
registryUrlNormalized,
repository
);
}
return await this.queryRegistryVersions(
serviceDiscovery,
registryUrlNormalized,
repository
);

(This next code snippet is only present in the queryRegistryExtendedApi() method)

if (res.source) {
dep.sourceUrl = res.source;
}

I propose that Renovate should always check for that source field (for other registries via queryRegistryVersions()), and use that value as the sourceUrl if it indeed contains a URL. The proposed implementation would look something like this:

  /**
   * this version uses the Module Registry Protocol that all registries are required to implement
   * https://www.terraform.io/internals/module-registry-protocol
   */
  private async queryRegistryVersions(
    serviceDiscovery: ServiceDiscoveryResult,
    registryUrl: string,
    repository: string
  ): Promise<ReleaseResult | null> {
    let res: TerraformModuleVersions;

    // ...

+   // Add the source URL if given
+   if (res.modules[0].source && validateUrl(res.modules[0].source)) {
+     dep.sourceUrl = res.modules[0].source;
+   }
+
    return dep;
  }

(Some other minor tweaks are also needed; this is just the important bit)

Basically, if a source key is found and it looks like a URL, let's assume it must be a source URL.

I have this working locally (along with an automated test) and would be glad to push up a PR if you're open to this change :)

@secustor secustor added type:feature Feature (new functionality) priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others datasource:terraform-module labels Oct 3, 2023
@HonkingGoose HonkingGoose added the status:in-progress Someone is working on implementation label Oct 4, 2023
@renovate-release
Copy link
Collaborator

🎉 This issue has been resolved in version 37.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
datasource:terraform-module priority-3-medium Default priority, "should be done" but isn't prioritised ahead of others status:in-progress Someone is working on implementation type:feature Feature (new functionality)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants