azure - Terraform 源错误 - 错误 : Failed to query available provider packages

标签 azure azure-devops devops terraform-provider-azure

我正在尝试使用 terraform 部署新的基础设施(这是第一次),但出现以下错误。我已经尝试了所有方法,但似乎没有任何方法可以解决问题。

看起来它正在请求提供商hashicorp/azure

谁能帮忙吗?

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]

我用来创建基础设施的代码如下:

  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
} 

我的 terraform 版本是:Terraform v1.1.5,我通过 bash 在 Azure CLI 上使用。

知道导致此问题的原因以及如何解决它吗?

谢谢!

最佳答案

当人们不小心在 required_providers block 中指定“hashicorp/azure”或“hashicorp/azurem”而不是“hashicorp/azurerm”时,通常会发生这种情况。您是否检查了“azure_instance”模块调用中引用的“vm”模块?那里可能指定了错误的“hashicorp/azure”。

关于azure - Terraform 源错误 - 错误 : Failed to query available provider packages,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71307245/

相关文章:

c# - Azure LDAP 与 DirectoryEntry "the server is not operational"错误 C#

azure - 如何在管道执行之间将运行时数据存储在 Azure 数据工厂中?

kubernetes - Kubernetes 集群上 Helm 安装或升级发布失败 : the server could not find the requested resource or UPGRADE FAILED: no deployed releases

azure - 逻辑应用程序直到 HTTP 调用收到 400 后循环中断

azure - 通过 Azure 应用服务使用 WebSocket 时的权衡?

SSH 服务连接 - 无法解析私钥 : Unsupported key format

asp.net - 如何在没有源代码管理凭据的情况下转换 web.config 中的 mailSettings

azure - Visual Studio Team Services 在 Azure 上部署 - 错误 default-publish.ps1 在 azure vm 上不存在

azure - 如何检查代理上运行管道的能力?

azure - 如何将 KeyVault secret 传递到 Azure Pipelines 中的模板或脚本文件?