2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

terraform initで「Failed to query available provider packages」が発生した時の対処法

Posted at

自宅サーバ用途でESXiを導入しました。WebからポチポチしてVMを立てるのは大変なので、terraformを使ってコードで管理しようと思います。

使用したプラグインは以下になります。

使用しているterraformのversionは以下になります。(Mac環境を使用しています)

$ terraform -v
Terraform v0.15.4
on darwin_amd64

エラー内容

はじめにterraform initで使用するprovider pluginの設定を行いますが、この時点でエラーが発生しました。

$ 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

使用したファイルは以下になります。

main.tf
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"
  }
}

対処法

source = "hashicorp/esxi"という指定が間違っていたので、source = "josenk/esxi"に修正して対処しました。(公式ドキュメントにも書いてありました、、)

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

terraform 0.13からProviderが https://registry.terraform.io/ から配布されるので、source = "<Provider名>/<プラグイン名>"と記載することで https://registry.terraform.io/ からプラグインを探しにいきます。

また、source = "registry.terraform.io/josenk/esxi"と記載しても同じ動作になります。

プラグインを使用する際には、レジストリのWebページにアクセスして右上の「USE PROVIDER」をクリックすると、必要なterraformのversionとコードが見れるので、表示された通りに記載すれば問題ないです。

terraform-registry-josenk-esxi.png

Reference

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?