How to use terraform modules in gitlab terrafrom registry

I have a repo for terraform module registry, I followed this doc
Terraform module registry | GitLab to upload modules to registry. It seems working fine, and I can see all the modules I uploaded in
https://selfhosted-gitlab.com/group/sub-group/terraform-modules/-/infrastructure_registry

Now I have another repository trying to use modules in it. This seems to fail.


Initializing modules...
2021-10-07T13:19:40.163Z [DEBUG] Module installer: begin sns_pagerduty
2021-10-07T13:19:40.163Z [DEBUG] sns_pagerduty listing available versions of elfhosted-gitlab.com/group/sns/aws at selfhosted-gitlab.com
2021-10-07T13:19:40.163Z [DEBUG] Service discovery for selfhosted-gitlab.com at https://selfhosted-gitlab.com/.well-known/terraform.json
β•·
β”‚ Error: Error accessing remote module registry
β”‚
β”‚ Failed to retrieve available versions for module "sns_pagerduty" (sns.tf:1) from selfhosted-gitlab.com: host does not provide a modules
β”‚ service.
β•΅

β•·
β”‚ Error: Error accessing remote module registry
β”‚
β”‚ Failed to retrieve available versions for module "sns_pagerduty" (sns.tf:1) from selfhosted-gitlab.com: host does not provide a modules
β”‚ service.
β•΅

I tried many hacks like changing
~/.terrafromrc to have these

host "selfhosted-gitlab.com" {
  services = {
    "modules.v1" = "https://selfhosted-gitlab.com/projects/410/packages/terraform/modules"
  }
}

then I get this error

Initializing modules...
2021-10-07T13:20:42.391Z [DEBUG] Module installer: begin sns_pagerduty
2021-10-07T13:20:42.391Z [DEBUG] sns_pagerduty listing available versions of selfhosted-gitlab.com/group/sns/aws at selfhosted-gitlab.com
2021-10-07T13:20:42.391Z [DEBUG] fetching module versions from "https://selfhosted-gitlab.com/projects/410/packages/terraform/modules/group/sns/aws/versions"
2021-10-07T13:20:42.391Z [DEBUG] GET https://selfhosted-gitlab.com/projects/410/packages/terraform/modules/group/sns/aws/versions
β•·
β”‚ Error: Error accessing remote module registry
β”‚
β”‚ Failed to retrieve available versions for module "sns_pagerduty" (sns.tf:1) from selfhosted-gitlab.com: invalid character '<' looking for
β”‚ beginning of value.
β•΅

β•·
β”‚ Error: Error accessing remote module registry
β”‚
β”‚ Failed to retrieve available versions for module "sns_pagerduty" (sns.tf:1) from selfhosted-gitlab.com: invalid character '<' looking for
β”‚ beginning of value.
β•΅

As far I understand, terraform discovery doesn’t work with GitLab, But terrafomrc hack also failing to list versions of module.

Or Am I using this wrongly.

Can anyone help me?

GitLab version : 14.2.3 CE
Self hosted.
Terraform version : 1.0.8

Not: selfhosted-gitlab.com is just made host.

1 Like

Did you find the bug?

Found my error. credentials files misplaced. :slight_smile: