Can't apply when using gitlab provider

I am using terraform docker image hashicorp/terraform:latest and I define the provider in main.tf as following:


terraform {
  required_providers {
    gitlab = {
      source = "gitlabhq/gitlab"
      version = "3.3.0"
    }
  }
}

provider "gitlab" {
    token = var.gitlab_token
}

when I run terraform apply, I become the following error:

Initializing provider plugins...
- Finding gitlabhq/gitlab versions matching "3.3.0"...
- Finding latest version of hashicorp/aws...
- Finding latest version of hashicorp/gitlab...
- Installing gitlabhq/gitlab v3.3.0...
- Installed gitlabhq/gitlab v3.3.0 (signed by a HashiCorp partner, key ID BC097C3333027B14)
- Installing hashicorp/aws v3.22.0...
- Installed hashicorp/aws v3.22.0 (signed by HashiCorp)
Partner and community providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://www.terraform.io/docs/plugins/signing.html
Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider
hashicorp/gitlab: provider registry registry.terraform.io does not have a
provider named registry.terraform.io/hashicorp/gitlab
If you have just upgraded directly from Terraform v0.12 to Terraform v0.14
then please upgrade to Terraform v0.13 first and follow the upgrade guide for
that release, which might help you address this problem.
Did you intend to use gitlabhq/gitlab? If so, you must specify that source
address in each module which requires that provider. To see which modules are
currently depending on hashicorp/gitlab, run the following command:
    terraform providers

I can’t find anything on solving this issue in the documentation.

terraform --version
Terraform v0.14.3

1 Like

I am commenting to have this serve as a bookmark, I have run into a similar issue and would appreciate any help!

Hello, two years later!

The error message in the original question is reporting that there is no provider named hashicorp/gitlab.

For backward compatibility for modules that were written before Terraform supported third-party provider namespaces, Terraform assumes that any provider whose dependency isn’t explicitly declared is intended to belong to the hashicorp namespace. But this isn’t an official provider and so that is not a correct assumption here.

The error message includes a suggestion which I believe is correct in this case:

Did you intend to use gitlabhq/gitlab? If so, you
must specify that source address in each module
which requires that provider. To see which modules
are currently depending on hashicorp/gitlab, run
the following command:
    terraform providers

What this recommendation is suggesting to do is:

  1. Run terraform providers in the same directory where you ran terraform init, which should produce a list of all of the provider dependencies Terraform was able to detect across all modules in this configuration.

  2. Look in that list for any reference to hashicorp/gitlab, and make a list of all of the modules which include that dependency.

  3. In one of the .tf files for each of the modules from the previous step, declare that the local name “gitlab” is intended to mean gitlabhq/gitlab rather than hashicorp/gitlab:

    terraform {
      required_providers {
        gitlab = {
          source = "gitlabhq/gitlab"
        }
      }
    }
    

    If you don’t already have a required_providers block in each module then the conventional file to add it in is versions.tf, but that’s just idiom and not actually required by Terraform. It’s fine to just add the gitlab entry to an existing required_providers directive in some other file in your module you already have one.

1 Like