Search code examples
azureterraforminfrastructure-as-code

Terraform: Failed to query available provider packages (Azapi)


I try to use the Azure/Azapi Provider within my Terraform project but after I add the provider and run terraform init, I get the following error:

Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider hashicorp/azapi: provider registry registry.terraform.io does not have a provider named registry.terraform.io/hashicorp/azapi 

This is how my providers.tf looks like:

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "=3.16.0"
    }
    azapi = {
      source  = "azure/azapi"
      version = "=0.4.0"
    }

  }

  required_version = "=1.2.6"
}

provider "azurerm" {
  features {}
}

provider "azapi" {
}

When I run terraform providers, I can see that the provider has a wrong registry URL within my module:

├── module.az-aca-env
│   └── provider[registry.terraform.io/hashicorp/azapi]

I would expect something like registry.terraform.io/azure/azapi.

Any ideas?


Solution

  • Okay, I found a workaround. I have to add a providers.tf inside my module directory (/modules/az-aca-env) with the following content:

    terraform {
      required_providers {
        azapi = {
          source  = "Azure/azapi"
          version = "=0.4.0"
        }
      }
    }
    

    After adding it, the terraform init works ✅.