Automatically publish tagged releases to the GitLab terraform registry
Note that the pipeline for this MR will fail until uis/devops/continuous-delivery/ci-templates!28 (closed) is merged.
An example of a semver tagged module published via this CI configuration is at https://gitlab.developers.cam.ac.uk/uis/devops/infra/terraform/gcp-function/-/infrastructure_registry/418
This was published by https://gitlab.developers.cam.ac.uk/uis/devops/infra/terraform/gcp-function/-/pipelines/106036.
Closes #1 (closed)
Merge request reports
Activity
assigned to @rjw57
28 29 29 30 ```tf 30 31 module "hello-world" { 31 source = "..." 32 source = "gitlab.developers.cam.ac.uk/uis/gcp-function/google" I'd say so but then https://gitlab.developers.cam.ac.uk/uis/devops/infra/terraform/gcp-function/-/infrastructure_registry/418 suggests not. Let me do a bit of experimentation...
https://docs.gitlab.com/ee/user/packages/terraform_module_registry/#reference-a-terraform-module claims it takes the form:
source = "gitlab.com/<namespace>/<module_name>/<module_system>"
so may be only accepts single path namespaces? Not sure where<module_system>
comes from.One upstream issue: https://gitlab.com/gitlab-org/gitlab/-/issues/335672
At least two more: https://gitlab.com/gitlab-org/gitlab/-/issues/335671 https://gitlab.com/gitlab-org/gitlab/-/issues/335461
Looks like another Gitlab feature that needs a bit of time to settle.
I think it's a problem with the registry protocol itself. Terraform mandates the format: https://www.terraform.io/docs/cloud/registry/using.html
Module source strings are slightly different. The public registry uses a three-part
<NAMESPACE>/<MODULE NAME>/<PROVIDER>
format, and private modules use a four-part<HOSTNAME>/<ORGANIZATION>/<MODULE NAME>/<PROVIDER>
format.So I think GitLab is sort of right here. Certainly if I try to use the full URL I get:
Error: Invalid version constraint Cannot apply a version constraint to module "hello-world" (at hello.tf:1) because it has a non Registry URL.
whereas using the "shorter" string gets me
Error: Failed to download module Could not download module "hello-world" (hello.tf:1) source code from "https://gitlab.developers.cam.ac.uk/api/v4/packages/terraform/modules/v1/uis/gcp-function/google/1.0.2-rc.1/file?token=[...]&archive=tgz": bad response code: 401.
which is slightly more progress. (I've not tried adding credentials in yet.)
requested review from @rjg21