Why dus it keep trying to install 3d party providers form the main hashicorp repo and failing

Hi i have been debugging a issue ware terraform keeps trying to install 3d party providers form the main hashicorp repo. but it also finds the correct repo but still fails giving the following error

Error: Failed to query available provider packages
│ 
│ Could not retrieve the list of available versions for provider hashicorp/mysql: provider registry registry.terraform.io does not have a provider named registry.terraform.io/hashicorp/mysql
│ 
│ Did you intend to use petoju/mysql? If so, you must specify that source address in each module which requires that provider. To see which modules are currently depending on hashicorp/mysql, run the following command:
│     terraform providers
╵

google and chatgpt has failed me so far. and taking a look around here i cant find the answer either. removed the lockfile and the .terraform folder. but with no luck. checked the hole repo for any further mentions of this plugin. and there is non to be found.

i also have run a full trace on the init. witch can be found below

Initializing provider plugins...
- Finding hashicorp/null versions matching "~> 2.1.2"...
2025-02-17T10:22:45.084+0100 [DEBUG] Service discovery for registry.terraform.io at https://registry.terraform.io/.well-known/terraform.json
2025-02-17T10:22:45.084+0100 [TRACE] HTTP client GET request to https://registry.terraform.io/.well-known/terraform.json
2025-02-17T10:22:45.138+0100 [DEBUG] GET https://registry.terraform.io/v1/providers/hashicorp/null/versions
2025-02-17T10:22:45.138+0100 [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/hashicorp/null/versions
- Finding latest version of hashicorp/mysql...
2025-02-17T10:22:45.169+0100 [DEBUG] GET https://registry.terraform.io/v1/providers/hashicorp/mysql/versions
2025-02-17T10:22:45.169+0100 [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/hashicorp/mysql/versions
- Finding hashicorp/random versions matching "3.6.3"...
2025-02-17T10:22:45.595+0100 [DEBUG] GET https://registry.terraform.io/v1/providers/hashicorp/random/versions
2025-02-17T10:22:45.595+0100 [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/hashicorp/random/versions
- Finding hashicorp/azurerm versions matching "~> 3.31.0"...
2025-02-17T10:22:45.625+0100 [DEBUG] GET https://registry.terraform.io/v1/providers/hashicorp/azurerm/versions
2025-02-17T10:22:45.625+0100 [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/hashicorp/azurerm/versions
- Finding petoju/mysql versions matching "3.0.69"...
2025-02-17T10:22:45.664+0100 [DEBUG] GET https://registry.terraform.io/v1/providers/petoju/mysql/versions
2025-02-17T10:22:45.664+0100 [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/petoju/mysql/versions
2025-02-17T10:22:45.700+0100 [TRACE] providercache.fillMetaCache: scanning directory .terraform/providers
2025-02-17T10:22:45.700+0100 [TRACE] getproviders.SearchLocalDirectory: failed to resolve symlinks for .terraform/providers: lstat .terraform/providers: no such file or directory
2025-02-17T10:22:45.700+0100 [TRACE] providercache.fillMetaCache: error while scanning directory .terraform/providers: cannot search .terraform/providers: lstat .terraform/providers: no such file or directory
2025-02-17T10:22:45.700+0100 [DEBUG] GET https://registry.terraform.io/v1/providers/hashicorp/null/2.1.2/download/linux/amd64
2025-02-17T10:22:45.700+0100 [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/hashicorp/null/2.1.2/download/linux/amd64
2025-02-17T10:22:45.732+0100 [DEBUG] GET https://releases.hashicorp.com/terraform-provider-null/2.1.2/terraform-provider-null_2.1.2_SHA256SUMS
2025-02-17T10:22:45.732+0100 [TRACE] HTTP client GET request to https://releases.hashicorp.com/terraform-provider-null/2.1.2/terraform-provider-null_2.1.2_SHA256SUMS
2025-02-17T10:22:45.783+0100 [DEBUG] GET https://releases.hashicorp.com/terraform-provider-null/2.1.2/terraform-provider-null_2.1.2_SHA256SUMS.72D7468F.sig
2025-02-17T10:22:45.783+0100 [TRACE] HTTP client GET request to https://releases.hashicorp.com/terraform-provider-null/2.1.2/terraform-provider-null_2.1.2_SHA256SUMS.72D7468F.sig
- Installing hashicorp/null v2.1.2...
2025-02-17T10:22:45.793+0100 [TRACE] providercache.Dir.InstallPackage: installing registry.terraform.io/hashicorp/null v2.1.2 from https://releases.hashicorp.com/terraform-provider-null/2.1.2/terraform-provider-null_2.1.2_linux_amd64.zip
2025-02-17T10:22:45.793+0100 [TRACE] HTTP client GET request to https://releases.hashicorp.com/terraform-provider-null/2.1.2/terraform-provider-null_2.1.2_linux_amd64.zip
2025-02-17T10:22:46.168+0100 [DEBUG] Provider signed by 34365D9472D7468F HashiCorp Security (hashicorp.com/security) <security@hashicorp.com>
2025-02-17T10:22:46.752+0100 [TRACE] providercache.fillMetaCache: scanning directory .terraform/providers
2025-02-17T10:22:46.752+0100 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/null v2.1.2 for linux_amd64 at .terraform/providers/registry.terraform.io/hashicorp/null/2.1.2/linux_amd64
2025-02-17T10:22:46.752+0100 [TRACE] providercache.fillMetaCache: including .terraform/providers/registry.terraform.io/hashicorp/null/2.1.2/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/null 2.1.2
- Installed hashicorp/null v2.1.2 (signed by HashiCorp)
2025-02-17T10:22:46.782+0100 [TRACE] providercache.fillMetaCache: using cached result from previous scan of .terraform/providers
2025-02-17T10:22:46.782+0100 [DEBUG] GET https://registry.terraform.io/v1/providers/hashicorp/random/3.6.3/download/linux/amd64
2025-02-17T10:22:46.782+0100 [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/hashicorp/random/3.6.3/download/linux/amd64
2025-02-17T10:22:46.814+0100 [DEBUG] GET https://releases.hashicorp.com/terraform-provider-random/3.6.3/terraform-provider-random_3.6.3_SHA256SUMS
2025-02-17T10:22:46.814+0100 [TRACE] HTTP client GET request to https://releases.hashicorp.com/terraform-provider-random/3.6.3/terraform-provider-random_3.6.3_SHA256SUMS
2025-02-17T10:22:46.841+0100 [DEBUG] GET https://releases.hashicorp.com/terraform-provider-random/3.6.3/terraform-provider-random_3.6.3_SHA256SUMS.72D7468F.sig
2025-02-17T10:22:46.841+0100 [TRACE] HTTP client GET request to https://releases.hashicorp.com/terraform-provider-random/3.6.3/terraform-provider-random_3.6.3_SHA256SUMS.72D7468F.sig
- Installing hashicorp/random v3.6.3...
2025-02-17T10:22:46.848+0100 [TRACE] providercache.Dir.InstallPackage: installing registry.terraform.io/hashicorp/random v3.6.3 from https://releases.hashicorp.com/terraform-provider-random/3.6.3/terraform-provider-random_3.6.3_linux_amd64.zip
2025-02-17T10:22:46.849+0100 [TRACE] HTTP client GET request to https://releases.hashicorp.com/terraform-provider-random/3.6.3/terraform-provider-random_3.6.3_linux_amd64.zip
2025-02-17T10:22:47.136+0100 [DEBUG] Provider signed by 34365D9472D7468F HashiCorp Security (hashicorp.com/security) <security@hashicorp.com>
2025-02-17T10:22:47.365+0100 [TRACE] providercache.fillMetaCache: scanning directory .terraform/providers
2025-02-17T10:22:47.365+0100 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/null v2.1.2 for linux_amd64 at .terraform/providers/registry.terraform.io/hashicorp/null/2.1.2/linux_amd64
2025-02-17T10:22:47.365+0100 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/random v3.6.3 for linux_amd64 at .terraform/providers/registry.terraform.io/hashicorp/random/3.6.3/linux_amd64
2025-02-17T10:22:47.365+0100 [TRACE] providercache.fillMetaCache: including .terraform/providers/registry.terraform.io/hashicorp/random/3.6.3/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/random 3.6.3
2025-02-17T10:22:47.365+0100 [TRACE] providercache.fillMetaCache: including .terraform/providers/registry.terraform.io/hashicorp/null/2.1.2/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/null 2.1.2
- Installed hashicorp/random v3.6.3 (signed by HashiCorp)
2025-02-17T10:22:47.387+0100 [TRACE] providercache.fillMetaCache: using cached result from previous scan of .terraform/providers
2025-02-17T10:22:47.387+0100 [DEBUG] GET https://registry.terraform.io/v1/providers/hashicorp/azurerm/3.31.0/download/linux/amd64
2025-02-17T10:22:47.387+0100 [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/hashicorp/azurerm/3.31.0/download/linux/amd64
2025-02-17T10:22:47.416+0100 [DEBUG] GET https://releases.hashicorp.com/terraform-provider-azurerm/3.31.0/terraform-provider-azurerm_3.31.0_SHA256SUMS
2025-02-17T10:22:47.416+0100 [TRACE] HTTP client GET request to https://releases.hashicorp.com/terraform-provider-azurerm/3.31.0/terraform-provider-azurerm_3.31.0_SHA256SUMS
2025-02-17T10:22:47.445+0100 [DEBUG] GET https://releases.hashicorp.com/terraform-provider-azurerm/3.31.0/terraform-provider-azurerm_3.31.0_SHA256SUMS.72D7468F.sig
2025-02-17T10:22:47.445+0100 [TRACE] HTTP client GET request to https://releases.hashicorp.com/terraform-provider-azurerm/3.31.0/terraform-provider-azurerm_3.31.0_SHA256SUMS.72D7468F.sig
- Installing hashicorp/azurerm v3.31.0...
2025-02-17T10:22:47.453+0100 [TRACE] providercache.Dir.InstallPackage: installing registry.terraform.io/hashicorp/azurerm v3.31.0 from https://releases.hashicorp.com/terraform-provider-azurerm/3.31.0/terraform-provider-azurerm_3.31.0_linux_amd64.zip
2025-02-17T10:22:47.453+0100 [TRACE] HTTP client GET request to https://releases.hashicorp.com/terraform-provider-azurerm/3.31.0/terraform-provider-azurerm_3.31.0_linux_amd64.zip
2025-02-17T10:22:49.057+0100 [DEBUG] Provider signed by 34365D9472D7468F HashiCorp Security (hashicorp.com/security) <security@hashicorp.com>
2025-02-17T10:22:51.745+0100 [TRACE] providercache.fillMetaCache: scanning directory .terraform/providers
2025-02-17T10:22:51.746+0100 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/azurerm v3.31.0 for linux_amd64 at .terraform/providers/registry.terraform.io/hashicorp/azurerm/3.31.0/linux_amd64
2025-02-17T10:22:51.746+0100 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/null v2.1.2 for linux_amd64 at .terraform/providers/registry.terraform.io/hashicorp/null/2.1.2/linux_amd64
2025-02-17T10:22:51.746+0100 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/random v3.6.3 for linux_amd64 at .terraform/providers/registry.terraform.io/hashicorp/random/3.6.3/linux_amd64
2025-02-17T10:22:51.746+0100 [TRACE] providercache.fillMetaCache: including .terraform/providers/registry.terraform.io/hashicorp/null/2.1.2/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/null 2.1.2
2025-02-17T10:22:51.746+0100 [TRACE] providercache.fillMetaCache: including .terraform/providers/registry.terraform.io/hashicorp/random/3.6.3/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/random 3.6.3
2025-02-17T10:22:51.746+0100 [TRACE] providercache.fillMetaCache: including .terraform/providers/registry.terraform.io/hashicorp/azurerm/3.31.0/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/azurerm 3.31.0
- Installed hashicorp/azurerm v3.31.0 (signed by HashiCorp)
2025-02-17T10:22:51.986+0100 [TRACE] providercache.fillMetaCache: using cached result from previous scan of .terraform/providers
2025-02-17T10:22:51.986+0100 [DEBUG] GET https://registry.terraform.io/v1/providers/petoju/mysql/3.0.69/download/linux/amd64
2025-02-17T10:22:51.986+0100 [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/petoju/mysql/3.0.69/download/linux/amd64
2025-02-17T10:22:52.016+0100 [DEBUG] GET https://github.com/petoju/terraform-provider-mysql/releases/download/v3.0.69/terraform-provider-mysql_3.0.69_SHA256SUMS
2025-02-17T10:22:52.016+0100 [TRACE] HTTP client GET request to https://github.com/petoju/terraform-provider-mysql/releases/download/v3.0.69/terraform-provider-mysql_3.0.69_SHA256SUMS
2025-02-17T10:22:52.253+0100 [TRACE] HTTP client GET request to https://objects.githubusercontent.com/github-production-release-asset-2e65be/339200406/52d13629-5f0f-4e4b-bd70-51bee2c46fb1?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20250217%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20250217T092252Z&X-Amz-Expires=300&X-Amz-Signature=8700a7b0a020f7abe581af6dab268d863a6b541e13297b2fc71658f175fb3e0d&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3B%20filename%3Dterraform-provider-mysql_3.0.69_SHA256SUMS&response-content-type=application%2Foctet-stream
2025-02-17T10:22:52.620+0100 [DEBUG] GET https://github.com/petoju/terraform-provider-mysql/releases/download/v3.0.69/terraform-provider-mysql_3.0.69_SHA256SUMS.sig
2025-02-17T10:22:52.620+0100 [TRACE] HTTP client GET request to https://github.com/petoju/terraform-provider-mysql/releases/download/v3.0.69/terraform-provider-mysql_3.0.69_SHA256SUMS.sig
2025-02-17T10:22:52.865+0100 [TRACE] HTTP client GET request to https://objects.githubusercontent.com/github-production-release-asset-2e65be/339200406/a49bbb80-adfd-412f-9315-09ca8217af06?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20250217%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20250217T092252Z&X-Amz-Expires=300&X-Amz-Signature=fc82519b1338cdf6081eac10d7f9b7421b1b62283e3c54fa288f8901c401b9bd&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3B%20filename%3Dterraform-provider-mysql_3.0.69_SHA256SUMS.sig&response-content-type=application%2Foctet-stream
- Installing petoju/mysql v3.0.69...
2025-02-17T10:22:53.276+0100 [TRACE] providercache.Dir.InstallPackage: installing registry.terraform.io/petoju/mysql v3.0.69 from https://github.com/petoju/terraform-provider-mysql/releases/download/v3.0.69/terraform-provider-mysql_3.0.69_linux_amd64.zip
2025-02-17T10:22:53.276+0100 [TRACE] HTTP client GET request to https://github.com/petoju/terraform-provider-mysql/releases/download/v3.0.69/terraform-provider-mysql_3.0.69_linux_amd64.zip
2025-02-17T10:22:53.584+0100 [TRACE] HTTP client GET request to https://objects.githubusercontent.com/github-production-release-asset-2e65be/339200406/8b72d2a9-350b-4db4-a4d2-43c4ff425d50?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=releaseassetproduction%2F20250217%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20250217T092253Z&X-Amz-Expires=300&X-Amz-Signature=c4ca6034b065441d3f90a38aa699939f7d3b0100f6a03d25fa231da398c4f014&X-Amz-SignedHeaders=host&response-content-disposition=attachment%3B%20filename%3Dterraform-provider-mysql_3.0.69_linux_amd64.zip&response-content-type=application%2Foctet-stream
2025-02-17T10:22:54.367+0100 [DEBUG] Provider signed by 298A405CE1C450D2 Peter Junos (yubi-saved key) <petoju@gmail.com>
2025-02-17T10:22:54.781+0100 [TRACE] providercache.fillMetaCache: scanning directory .terraform/providers
2025-02-17T10:22:54.781+0100 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/azurerm v3.31.0 for linux_amd64 at .terraform/providers/registry.terraform.io/hashicorp/azurerm/3.31.0/linux_amd64
2025-02-17T10:22:54.781+0100 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/null v2.1.2 for linux_amd64 at .terraform/providers/registry.terraform.io/hashicorp/null/2.1.2/linux_amd64
2025-02-17T10:22:54.781+0100 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/random v3.6.3 for linux_amd64 at .terraform/providers/registry.terraform.io/hashicorp/random/3.6.3/linux_amd64
2025-02-17T10:22:54.781+0100 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/petoju/mysql v3.0.69 for linux_amd64 at .terraform/providers/registry.terraform.io/petoju/mysql/3.0.69/linux_amd64
2025-02-17T10:22:54.781+0100 [TRACE] providercache.fillMetaCache: including .terraform/providers/registry.terraform.io/hashicorp/azurerm/3.31.0/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/azurerm 3.31.0
2025-02-17T10:22:54.781+0100 [TRACE] providercache.fillMetaCache: including .terraform/providers/registry.terraform.io/hashicorp/null/2.1.2/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/null 2.1.2
2025-02-17T10:22:54.781+0100 [TRACE] providercache.fillMetaCache: including .terraform/providers/registry.terraform.io/hashicorp/random/3.6.3/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/random 3.6.3
2025-02-17T10:22:54.781+0100 [TRACE] providercache.fillMetaCache: including .terraform/providers/registry.terraform.io/petoju/mysql/3.0.69/linux_amd64 as a candidate package for registry.terraform.io/petoju/mysql 3.0.69
- Installed petoju/mysql v3.0.69 (self-signed, key ID 298A405CE1C450D2)
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/cli/plugins/signing.html
╷

@wessel1512:

Here’s one way I can reproduce this exact behavior:

terraform {
  required_providers {
    mysql2 = {
      source = "petoju/mysql"
    }

    mysql = {
      source = "mysql"
    }
  }
}

provider "mysql" {
  # Configuration options
}

provider "mysql2" {
  # Configuration options
}

│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/mysql: provider registry registry.terraform.io does not have a provider named
│ registry.terraform.io/hashicorp/mysql
│
│ Did you intend to use petoju/mysql? If so, you must specify that source address in each module which requires that provider. To see which modules are
│ currently depending on hashicorp/mysql, run the following command:
│     terraform providers

Terraform will suggest petoju/mysql if two things are both true:

  • Your Terraform configuration is requesting a provider in a default namespace, e.g. “mysql” – in Terraform 0.12+, this translates to “hashicorp/mysql,” which does not exist

  • Somewhere else, possibly in a module, your Terraform configuration requires petoju/mysql.

So Terraform’s strategy is: “see if the user has another provider named in their requirements that is of the same type, and offer that as a suggestion.”

A required_providers block is the right way to tell Terraform to require petoju/mysql.

terraform {
  required_providers {
    mysql = {
      source = "petoju/mysql"
    }
  }
}

provider "mysql" {
  # Configuration options
}

-Baraa, Terraform Developer Experience

Hi Baraa

this is also what i have configured. but it seems that something still does not add up

terraform {
  # Backend config is loaded from backend-configs/<env>.conf
  backend "azurerm" {
  }

  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~>3.31.0"
    }
    mysql = {
      source = "petoju/mysql"
      version = "3.0.69"
    }
    random = {
      source = "hashicorp/random"
      version = "3.6.3"
    }
  }
}

provider "azurerm" {
  subscription_id = var.subscription_id
  tenant_id       = var.tenant_id
  features {}
}
provider "mysql" {
  endpoint = "${module.terraform_wordpress_infra.azurerm_mysql_flexible_server.site.fully_qualified_domain_name}:3306"
  username = var.mariadb_administrator_username
  password = var.mariadb_administrator_password
  
}
provider "random" {
  
}

data "azurerm_client_config" "current" {
}

i have also check if this gets mentioned somewhere else. but this is the only place ware source = and provider gets mentions in the code

Terraform would be looking for a mysql provider in the default namespace only in the situation where you haven’t declared in within required_providers. You can use the terraform providers command to show which modules or state is configured to look for the hashicorp/mysql.

except i cant i need the terraform innit command to load the backend config. and that fails so i cant run the terraform provider command. and as far as i can see this command only displays the current provider configuration. so don’t know how much i have on this command