Need help understanding "Provider type mismatch" error

I have made a change to a terraform module to use a different version of a module source:

module "resources" {
  providers = {
    snowflake.sys = snowflake.sys
    snowflake.sec = snowflake.sec
  }
-  source = "git::https://github.com/org/repo//terraform/modules/foo?ref=bar"
+  source = "git::https://github.com/org/repo//terraform/modules/foo?ref=baz"
   ...
   ...
}

When running terraform plan I got error

  ╷
  │ Error: Provider type mismatch
  │ 
  │   on resources.tf line 41, in module "resources":
  │   41:     snowflake.sys = snowflake.sys
  │ 
  │ The local name "snowflake.sys" in the root module represents provider
  │ "hashicorp/snowflake", but "snowflake.sys" in module.resources represents
  │ "snowflake-labs/snowflake".
  │ 
  │ Each provider has its own distinct configuration schema and provider types,
  │ so this module`s "snowflake.sys" can be assigned only a configuration for
  │ snowflake-labs/snowflake, which is not required by module.resources.
  ╵

This is very confusing to me. snowflake.sys in the root module is defined like so:

terraform {
  required_version = ">= 0.13"
  required_providers {
    snowflake = {
      source  = "snowflake-labs/snowflake"
      version = "0.83.1"
    }
    vault = {
      source  = "hashicorp/vault"
      version = "~> 3.0"
    }
  }
}

provider "vault" {
  namespace = "redacted"
}

data "vault_generic_secret" "vault_secrets_automation" {
  path = format("common/key-value/path/to/secret")
}

provider "snowflake" {
  user          = "user@example.com"
  alias         = "sys"
  account       = "xyz"
  private_key   = data.vault_generic_secret.vault_secrets_automation.data["key"]
  role          = "SYSADMIN"
  authenticator = "JWT"
}

As you can see I am using provider “snowflake-labs/snowflake” so I am confused by the error message:

The local name “snowflake.sys” in the root module represents provider “hashicorp/snowflake”

Can someone please explain to me why I’m getting this error because I simply don’t understand it.

Hi @jamiekt,

I’m not sure what’s going on there, does the terraform providers output give you any more information?

The only thing I can see is that you have a typo in your terraform block, which is missing a closing brace. That would normally cause parsing errors like Unclosed configuration block though, but maybe it’s related somehow.

Hi @jbardin ,
The typo was my fault. I copied the entirety of our terraform.tf file then removed the parts that were irrelevant for this question. I clearly made a mistake and removed one brace too many. I’ve now added it back the message above.

I ran terraform providers and got the same error message as above. However, I switched back to branch main in my repo, ran terraform providers again, and again got the same errors. This suggests that the cause of this error is not the change that I made in my branch.

I’ll continue investigating.

I am facing the similar issue as well.

│ The local name “snowflake.sys_admin” in the root module represents provider
│ “snowflake-labs/snowflake”, but “snowflake.sys_admin” in module.default
│ represents “hashicorp/snowflake”.

In the root module.

terraform {
  required_version = "1.8.5"
  backend "s3" {}
  required_providers {
    snowflake = {
      source  = "Snowflake-Labs/snowflake"
      version = "0.98"
    }
  }
}

provider "snowflake" {
  alias = "security_admin"
  role  = "SECURITYADMIN"
}

provider "snowflake" {
  alias = "sys_admin"
  role  = "SYSADMIN"
}

module "default" {
  source = "./defaults"
  providers = {
    snowflake.security_admin = snowflake.security_admin
    snowflake.sys_admin = snowflake.sys_admin
  }
}

Inside the sub module defaults

resource "snowflake_account_role" "role1" {
  provider = snowflake.security_admin
  name     = "role_name"
  comment  = "some comment"
}

Not sure why the modules.defaults is referring to hashicorp/snowflake which doesnot even exist. Any luck with this?

UPDATED: I managed to make it work by adding the terraform block again in the child module

Inside the child module defaults

terraform {
  required_providers {
    snowflake = {
      source  = "Snowflake-Labs/snowflake"
      version = "0.98"
      configuration_aliases = [snowflake.security, snowflake.system]
    }
  }
}

resource "snowflake_account_role" "role1" {
  provider = snowflake.security
  name     = "role_name"
  comment  = "some comment"
}

And remove the provider field when specifying module in root module

module "default" {
  source = "./defaults"
  providers = {
    snowflake.security = snowflake.security_admin
    snowflake.system     = snowflake.sys_admin
  }
}

@stntmaniiac, what does your required_providers look like within the default module source?

@jbardin Thanks for checking in. I have added the Updated section in the same comment and it is already resolved for me. Basically seems like custom providers like Snowflake which is not officially listed under hashicorp doesnot automatically pass the provider context to child modules. Even if I don’t have any alias and just a single snowflake provider, I must repeat the required_providers block in child modules.

1 Like

Thx for the explanation @stntmaniiac . After originally posting this thread I discovered the same, I had to add required_providers in module source. Apologies for not coming back here and updating accordingly.