Home > Software design >  Terraform: Failed to query available provider packages (Azapi)
Terraform: Failed to query available provider packages (Azapi)

Time:08-11

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?

CodePudding user response:

You have a typo in the provider name, it is Azure/azapi as per documentation [1]:

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

provider "azapi" {
  # Configuration options
}

You can always see how to use the provider if you click on the big purple button in the top right-hand corner saying USE PROVIDER.


[1] https://registry.terraform.io/providers/azure/azapi/latest/docs

CodePudding user response:

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 ✅.

  • Related