Home > Blockchain >  Terraform source error - Error: Failed to query available provider packages
Terraform source error - Error: Failed to query available provider packages

Time:03-02

I am trying to deploy a new infrastructure using terraform (for the first time) and I am getting the following error. I've tried everything but nothing seems to fix the issue.

Looks like it is asking for a provider hashicorp/azure ?

Can anyone help please??

Initializing provider plugins...
- Finding latest version of hashicorp/azure...
- Finding hashicorp/azurerm versions matching "2.98.0"...
- Installing hashicorp/azurerm v2.98.0...
- Installed hashicorp/azurerm v2.98.0 (signed by HashiCorp)
╷
│ Error: Failed to query available provider packages
│ 
│ Could not retrieve the list of available versions for provider hashicorp/azure: provider registry registry.terraform.io does not have a provider named registry.terraform.io/hashicorp/azure
│ 
│ Did you intend to use terraform-providers/azure? If so, you must specify that source address in each module which requires that provider. To see which modules are currently depending on hashicorp/azure, run the following command:
│     terraform providers
╵

lucas@Azure:~$ terraform providers

Providers required by configuration:
.
├── provider[registry.terraform.io/hashicorp/azurerm] 2.98.0
└── provider[registry.terraform.io/hashicorp/azure]

The code that I am using to create the infrastructure is the below:

  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "=2.98.0"
    }
  }
}

provider "azurerm" {
  features {}
  subscription_id = "910910be-a61e-4e1f-a72a-7e43456c0836"
}

# Create a resource group
resource "azurerm_resource_group" "rg" {
  name     = "default"
  location = "West Europe"
}

# Create a virtual network
resource "azurerm_virtual_network" "vpc" {
  name                = "default-network"
  resource_group_name = azurerm_resource_group.rg.name
  location            = azurerm_resource_group.rg.location
  address_space       = ["10.0.0.0/16"]
}

# Create frontend subnet
resource "azurerm_subnet" "subnet_frontend" {
  name                 = "internal"
  resource_group_name  = azurerm_resource_group.rg.name
  virtual_network_name = azurerm_virtual_network.vpc.name
  address_prefixes     = ["10.0.1.0/24"]
}

# Create backend subnet
resource "azurerm_subnet" "subnet_backend" {
  name                 = "internal"
  resource_group_name  = azurerm_resource_group.rg.name
  virtual_network_name = azurerm_virtual_network.vpc.name
  address_prefixes     = ["10.0.2.0/24"]
}

# Create frontend network interface
resource "azurerm_network_interface" "frontend_nic" {
  name                = "frontend_nic"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name

  ip_configuration {
    name                          = "internal"
    subnet_id                     = azurerm_subnet.subnet_frontend.id
    private_ip_address_allocation = "Dynamic"
  }
}

# Create backend network interface
resource "azurerm_network_interface" "backend_nic" {
  name                = "backend_nic"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name

  ip_configuration {
    name                          = "internal"
    subnet_id                     = azurerm_subnet.subnet_backend.id
    private_ip_address_allocation = "Dynamic"
  }
}

# Create frontend VM based on module
resource "azure_instance" "frontend" {
  source   = "./vm"
  name     = "frontend"
  rg       = module.azurerm_resource_group.rg.name
  location = module.azurerm_resource_group.rg.location
  nic      = module.azurerm_network_interface.frontend_nic
}

# Create backend VM based on module
resource "azure_instance" "backend" {
  source   = "./vm"
  name     = "backend"
  rg       = module.azurerm_resource_group.rg.name
  location = module.azurerm_resource_group.rg.location
  nic      = module.azurerm_network_interface.backend_nic
} 

My terraform version is: Terraform v1.1.5 and I am using on Azure CLI via bash.

Any idea of what is causing this issue and how to fix it?

Thanks!

CodePudding user response:

This often happens when one accidentally specifies "hashicorp/azure" instead of "hashicorp/azurerm" in the required_providers block. Did you check the "vm" module referenced in the "azure_instance" module calls? There might be an erroneous "hashicorp/azure" specified there.

  • Related