Search code examples
terraformterraform-provider-azureopentofu

OpenTofu fails to query provider packages


I'm using OpenTofu for the deployment of some basic Azure resources. When running tofu init I get the following error:

Initializing the backend...

Initializing provider plugins...
- Finding hashicorp/random versions matching "~> 3.0"...
- Finding latest version of hashicorp/azure...
- Finding hashicorp/azurerm versions matching "~> 4.0"...
- Installing hashicorp/random v3.6.3...
- Installed hashicorp/random v3.6.3 (signed, key ID 0C0AF313E5FD9F80)
- Installing hashicorp/azurerm v4.19.0...
- Installed hashicorp/azurerm v4.19.0 (signed, key ID 0C0AF313E5FD9F80)

Providers are signed by their developers.
If you'd like to know more about provider signing, you can read about it here:
https://opentofu.org/docs/cli/plugins/signing/
╷
│ Error: Failed to query available provider packages
│ 
│ Could not retrieve the list of available versions for provider hashicorp/azure: provider registry
│ registry.opentofu.org does not have a provider named registry.opentofu.org/hashicorp/azure
│ 
│ All modules should specify their required_providers so that external consumers will get the correct providers when
│ using a module. To see which modules are currently depending on hashicorp/azure, run the following command:
│     tofu providers
│ 
│ If you believe this provider is missing from the registry, please submit a issue on the OpenTofu Registry
│ https://github.com/opentofu/registry/issues/new/choose

Things I've tried:

  • deleting the lock file and running it again
  • expressly using the terraform registry as opposed to the OpenTofu one using a .config and setting the environment variable TF_REGISTRY_DISCOVERY=1
  • updating the azurerm provider to ~>4.0
  • searching for any other references to hashicorps\azure (there are none)

The output of tofu providers is this:

Providers required by configuration:
.
├── provider[registry.opentofu.org/hashicorp/azurerm] ~> 4.0
├── provider[registry.opentofu.org/hashicorp/random] ~> 3.0
└── provider[registry.opentofu.org/hashicorp/azure]

and this is the contents of my providers file:

terraform {
  required_providers {    
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 3.0"
    }
    random = {
      source  = "hashicorp/random"
      version = "~> 3.0"
    }
  }
}

provider "azurerm" {
  features {
  }
}

I've exhausted all of ChatGPT's ideas so anything you can think of would be helpful.


Solution

  • It seems that somewhere in your configuration you have a resource that is declared with a resource type that starts with azure_ instead of azurerm_, and so OpenTofu is guessing that you are trying to use a provider named hashicorp/azure in an attempt to be backward-compatible with old modules written for very old versions of HashiCorp Terraform from before there were multiple namespaces for providers and so all providers were effectively in the "hashicorp" namespace.

    If you find that resource block and correct its resource type to have the azurerm_ prefix instead then this spurious dependency should no longer be detected.