Terraform 源错误 - 错误:无法查询可用的提供程序包

luc*_*grm 6 azure devops azure-devops terraform-provider-azure

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

\n

看起来它正在要求提供者hashicorp/azure

\n

有人可以帮忙吗?

\n
Initializing provider plugins...\n- Finding latest version of hashicorp/azure...\n- Finding hashicorp/azurerm versions matching "2.98.0"...\n- Installing hashicorp/azurerm v2.98.0...\n- Installed hashicorp/azurerm v2.98.0 (signed by HashiCorp)\n\xe2\x95\xb7\n\xe2\x94\x82 Error: Failed to query available provider packages\n\xe2\x94\x82 \n\xe2\x94\x82 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\n\xe2\x94\x82 \n\xe2\x94\x82 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:\n\xe2\x94\x82     terraform providers\n\xe2\x95\xb5\n\nlucas@Azure:~$ terraform providers\n\nProviders required by configuration:\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 provider[registry.terraform.io/hashicorp/azurerm] 2.98.0\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 provider[registry.terraform.io/hashicorp/azure]\n
Run Code Online (Sandbox Code Playgroud)\n

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

\n
  required_providers {\n    azurerm = {\n      source  = "hashicorp/azurerm"\n      version = "=2.98.0"\n    }\n  }\n}\n\nprovider "azurerm" {\n  features {}\n  subscription_id = "910910be-a61e-4e1f-a72a-7e43456c0836"\n}\n\n# Create a resource group\nresource "azurerm_resource_group" "rg" {\n  name     = "default"\n  location = "West Europe"\n}\n\n# Create a virtual network\nresource "azurerm_virtual_network" "vpc" {\n  name                = "default-network"\n  resource_group_name = azurerm_resource_group.rg.name\n  location            = azurerm_resource_group.rg.location\n  address_space       = ["10.0.0.0/16"]\n}\n\n# Create frontend subnet\nresource "azurerm_subnet" "subnet_frontend" {\n  name                 = "internal"\n  resource_group_name  = azurerm_resource_group.rg.name\n  virtual_network_name = azurerm_virtual_network.vpc.name\n  address_prefixes     = ["10.0.1.0/24"]\n}\n\n# Create backend subnet\nresource "azurerm_subnet" "subnet_backend" {\n  name                 = "internal"\n  resource_group_name  = azurerm_resource_group.rg.name\n  virtual_network_name = azurerm_virtual_network.vpc.name\n  address_prefixes     = ["10.0.2.0/24"]\n}\n\n# Create frontend network interface\nresource "azurerm_network_interface" "frontend_nic" {\n  name                = "frontend_nic"\n  location            = azurerm_resource_group.rg.location\n  resource_group_name = azurerm_resource_group.rg.name\n\n  ip_configuration {\n    name                          = "internal"\n    subnet_id                     = azurerm_subnet.subnet_frontend.id\n    private_ip_address_allocation = "Dynamic"\n  }\n}\n\n# Create backend network interface\nresource "azurerm_network_interface" "backend_nic" {\n  name                = "backend_nic"\n  location            = azurerm_resource_group.rg.location\n  resource_group_name = azurerm_resource_group.rg.name\n\n  ip_configuration {\n    name                          = "internal"\n    subnet_id                     = azurerm_subnet.subnet_backend.id\n    private_ip_address_allocation = "Dynamic"\n  }\n}\n\n# Create frontend VM based on module\nresource "azure_instance" "frontend" {\n  source   = "./vm"\n  name     = "frontend"\n  rg       = module.azurerm_resource_group.rg.name\n  location = module.azurerm_resource_group.rg.location\n  nic      = module.azurerm_network_interface.frontend_nic\n}\n\n# Create backend VM based on module\nresource "azure_instance" "backend" {\n  source   = "./vm"\n  name     = "backend"\n  rg       = module.azurerm_resource_group.rg.name\n  location = module.azurerm_resource_group.rg.location\n  nic      = module.azurerm_network_interface.backend_nic\n} \n
Run Code Online (Sandbox Code Playgroud)\n

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

\n

知道是什么导致了这个问题以及如何解决它吗?

\n

谢谢!

\n

cdu*_*dub 9

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


归档时间:

查看次数:

6590 次

最近记录:

2 年 前