Add latest version download endpoint for Terraform Module registry
What does this MR do and why?
Describe in detail what your merge request does and why.
Relates #344572 (closed)
Implements <base_url>/:namespace/:name/:provider/download
endpoint, which facilitates downloading the latest version of a Terraform module. Under the hoods it redirects to the specific version download endpoint, passing through the latest module version
Screenshots or screen recordings
I've manually pushed a version of a terraform module in a new gitlab-org/tf-module
project in the MR Gitpod instance. Example curl execution running against it:
curl --header "PRIVATE-TOKEN: <private_token>" -Lv https://3000-renehernandez-gitlab-otwppp9fncd.ws-us47.gitpod.io/api/v4/packages/terraform/modules/v1/gitlab-org/tf-module/gitlab/download
* Trying 34.168.230.177:443...
* Connected to 3000-renehernandez-gitlab-otwppp9fncd.ws-us47.gitpod.io (34.168.230.177) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/ssl/cert.pem
* CApath: none
* (304) (OUT), TLS handshake, Client hello (1):
* (304) (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use h2
* Server certificate:
* subject: CN=ws-us47.gitpod.io
* start date: Jun 6 19:13:46 2022 GMT
* expire date: Sep 4 19:13:45 2022 GMT
* subjectAltName: host "3000-renehernandez-gitlab-otwppp9fncd.ws-us47.gitpod.io" matched cert's "*.ws-us47.gitpod.io"
* issuer: C=US; O=Let's Encrypt; CN=R3
* SSL certificate verify ok.
* Using HTTP2, server supports multiplexing
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7fc1e8811400)
> GET /api/v4/packages/terraform/modules/v1/gitlab-org/tf-module/gitlab/download HTTP/2
> Host: 3000-renehernandez-gitlab-otwppp9fncd.ws-us47.gitpod.io
> user-agent: curl/7.79.1
> accept: */*
> private-token: <private_token>
>
* Connection state changed (MAX_CONCURRENT_STREAMS == 250)!
< HTTP/2 302
< cache-control: no-cache
< content-type: text/plain
< date: Mon, 20 Jun 2022 13:45:34 GMT
< location: /api/v4/packages/terraform/modules/v1/gitlab-org/tf-module/gitlab/1.0.1/download
< vary: Origin
< x-content-type-options: nosniff
< x-request-id: 01G60NRRYQ6F8BXSZZT5MC1WXM
< x-runtime: 9.554209
< content-length: 127
<
* Ignoring the response-body
* Connection #0 to host 3000-renehernandez-gitlab-otwppp9fncd.ws-us47.gitpod.io left intact
* Issue another request to this URL: 'https://3000-renehernandez-gitlab-otwppp9fncd.ws-us47.gitpod.io/api/v4/packages/terraform/modules/v1/gitlab-org/tf-module/gitlab/1.0.1/download'
* Found bundle for host 3000-renehernandez-gitlab-otwppp9fncd.ws-us47.gitpod.io: 0x600002d547e0 [can multiplex]
* Re-using existing connection! (#0) with host 3000-renehernandez-gitlab-otwppp9fncd.ws-us47.gitpod.io
* Connected to 3000-renehernandez-gitlab-otwppp9fncd.ws-us47.gitpod.io (34.168.230.177) port 443 (#0)
* Using Stream ID: 3 (easy handle 0x7fc1e8811400)
> GET /api/v4/packages/terraform/modules/v1/gitlab-org/tf-module/gitlab/1.0.1/download HTTP/2
> Host: 3000-renehernandez-gitlab-otwppp9fncd.ws-us47.gitpod.io
> user-agent: curl/7.79.1
> accept: */*
> private-token: <private_token>
>
< HTTP/2 204
< cache-control: no-cache
< date: Mon, 20 Jun 2022 13:45:34 GMT
< vary: Origin
< x-content-type-options: nosniff
< x-request-id: 01G60NS2DS04VF3XE88CVDBDT0
< x-runtime: 0.151138
< x-terraform-get: /api/v4/packages/terraform/modules/v1/gitlab-org/tf-module/gitlab/1.0.1/file?token=&archive=tgz
<
* Connection #0 to host 3000-renehernandez-gitlab-otwppp9fncd.ws-us47.gitpod.io left intact
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
- Save a TF module in a repository registry
-
curl
thehttps://<base_url>/api/v4/packages/terraform/modules/v1/<module_namespace>/<module_name>/<module_provider>/download>
endpoint
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by René Hernández Remedios