terraform-provider-gitlab icon indicating copy to clipboard operation
terraform-provider-gitlab copied to clipboard

Passing provider to grand child module gives error

Open BastienFerrier opened this issue 1 year ago • 4 comments

GitLab Provider version

3.16.1

GitLab version

No response

Terraform version

No response

Relevant Terraform Configuration

├── provider[registry.terraform.io/gitlabhq/gitlab] 3.16.1
├── provider[registry.terraform.io/hashicorp/aws] ~> 4.21
├── provider[registry.terraform.io/arthurhlt/zipper] ~> 0.14.0
├── provider[registry.terraform.io/hashicorp/null] ~> 3.0.0
└── module.environment
    ├── module.app
    │   ├── module.api
    │   │   ├── provider[registry.terraform.io/hashicorp/aws]
    │   │   └── module.resource
    │   │       ├── provider[registry.terraform.io/hashicorp/aws]
    │   │       ├── module.api_lambda
    │   │       │   ├── provider[registry.terraform.io/hashicorp/aws]
    │   │       │   └── module.permissions
    │   │       │       └── provider[registry.terraform.io/hashicorp/aws]
    │   │       └── module.method
    │   │           └── provider[registry.terraform.io/hashicorp/aws]
    │   └── module.gitlab
    │       └── provider[registry.terraform.io/hashicorp/gitlab]
    └── module.cognito
        └── provider[registry.terraform.io/hashicorp/aws]

Relevant log output

│ Error: Provider type mismatch
│
│   on tf-main.tf line 63, in module "environment":
│   63:           gitlab = gitlab
│
│ The local name "gitlab" in the root module represents provider "gitlabhq/gitlab", but "gitlab" in module.dev-dev represents "hashicorp/gitlab".
│
│ Each provider has its own distinct configuration schema and provider types, so this module's "gitlab" can be assigned only a configuration for hashicorp/gitlab, which is not required by module.environment.

Description

Hello all,

I'm posting here an error I get from Terraform while trying to cascade providers to modules.

I'm using several providers to build my state :

  • AWS
  • GitLab
  • Others

I'm provisioning multiple environments in the cloud so the architecture of terraform is built on module with tree configuration. On a module that is grand child (level -3) I'm deploying gitlab resources:

  • Creating a branch
  • Uploading a file in the branch This module doesn't work because the provider used is "hashicorp/gitlab" where it should be "gitlabhq/gitlab". In order to solve that I tried to cascade providers in module using meta argument: providers = { aws = aws gitlab = gitlab zipper = zipper } When doing that I get following error: │ The local name "gitlab" in the root module represents provider "gitlabhq/gitlab", but "gitlab" in module.dev-dev represents "hashicorp/gitlab".

This error is only on gitlab provider, AWS provider works fine.

Any help or explanation would be much appreciated.

Thanks' a lot

BastienFerrier avatar Sep 21 '22 06:09 BastienFerrier

but "gitlab" in module.dev-dev represents "hashicorp/gitlab".

How did you declare the gitlab provider in the module.dev-dev ? From the error message it seems you either didn't (defaulted to hashicorp/<x>) or you manually specified hashicorp. However, the provider is in the gitlabhq org.

Something like the following in the module will probably help:

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

aws and others may work because they are actually published in the hashicorp org.

timofurrer avatar Sep 21 '22 07:09 timofurrer

Thanks' for your feedback and help. "others may work because they are actually published in the hashicorp org." --> this is what I understood but I don't know how to provide explicit provider. Here is the config: required_providers {

  gitlab = {
    source = "gitlabhq/gitlab"
    version = "3.16.1"
  }
  aws = {
    source  = "hashicorp/aws"
    version = "~> 4.21"
  }

BastienFerrier avatar Sep 21 '22 08:09 BastienFerrier

@BastienFerrier Is that how it is defined in the sub module to which you want to pass gitlab to?

timofurrer avatar Sep 21 '22 08:09 timofurrer

I'm passing it this way:

module dev-dev {
  source = "./Modules/Env_Deployment"
    providers = {
      aws = aws
      gitlab = gitlab
      }

BastienFerrier avatar Sep 21 '22 08:09 BastienFerrier