当terraform init出现“Failed to query available provider packages”错误时的解决方法

我已经在家用服务器上安装了ESXi。由于通过网页逐个创建虚拟机非常麻烦,所以我打算使用terraform以代码的方式进行管理。

以下是使用的插件。

    • Registry: josenk/esxi | Terraform Registry

GitHub: josenk/terraform-provider-esxi: Terraform-provider-esxi plugin

我正在使用的 Terraform 版本如下(在 Mac 环境下使用)。

$ terraform -v
Terraform v0.15.4
on darwin_amd64

报错信息

首先,我们将进行与terraform init使用的提供程序插件的配置,但在这个阶段出现了错误。

$ terraform init

Initializing the backend...

Initializing provider plugins...
- Finding latest version of hashicorp/esxi...
╷
│ Error: Failed to query available provider packages
│ 
│ Could not retrieve the list of available versions for provider hashicorp/esxi: provider registry registry.terraform.io does not have a
│ provider named registry.terraform.io/hashicorp/esxi
│ 
│ All modules should specify their required_providers so that external consumers will get the correct providers when using a module. To see
│ which modules are currently depending on hashicorp/esxi, run the following command:
│     terraform providers

使用的文件如下所示。

terraform {
  required_providers {
    esxi = {
      source = "hashicorp/esxi"
    }
  }
}

provider "esxi" {
  esxi_hostname      = "192.168.0.2" # ESXiのIPアドレス
  esxi_hostport      = "22"
  esxi_hostssl       = "443"
  esxi_username      = "root" # ESXiにSSHするときのUSER
  esxi_password      = "pa$$w0rd" # ESXiにSSHするときのPASSWORD
}

resource "esxi_guest" "vmtest" {
  guest_name         = "vmtest"
  disk_store         = "datastore1"
  network_interfaces {
    virtual_network = "VM Network"
    mac_address     = "00:50:56:00:00:00"
  }
}

处理方法 (duì chǔ fǎ)

由于指定错误,我已经将”hashicorp/esxi”更正为”josenk/esxi”来处理。(在官方文档中也有提到、、)

terraform {
  required_providers {
    esxi = {
      source = "josenk/esxi" # ここを修正
    }
  }
}

从Terraform 0.13版本开始,我们可以通过在”source”字段中写入”<提供者名称>/<插件名称>”来从 https://registry.terraform.io/ 上找到相应的插件。

另外,即使将源设置为 “registry.terraform.io/josenk/esxi”,也会有相同的操作。

在使用插件时,您可以访问注册表网页,并点击右上角的“使用提供者”按钮,即可查看所需的terraform版本和代码,只需按照显示的内容进行描述即可,没有问题。

terraform-registry-josenk-esxi.png

请将以下内容用中文进行释义,只需给出一个选项:

Reference

参考资料

    • terraform 0.13でローカルproviderを利用する方法 – Sionの技術ブログ

 

    could not query provider registry for registry.terraform.io でterraformのproviderがダウンロードできない問題の対処 – Screaming Loud
广告
将在 10 秒后关闭
bannerAds