我正在尝试安装这个“愚蠢的”api 提供程序,以允许我将 Terraform 与当前在注册表中没有可用提供程序的 api 一起使用:
https://github.com/Mastercard/terraform-provider-restapi
我已经下载了最新版本的 .zipcURL
并使用提取了可执行文件chmod +x
。
按照 Hashicorp 的文档,我~/.terraformrc
通过显式安装方法创建了一个所需的配置文件,其内容如下:
provider_installation {
filesystem_mirror {
path = "/home/lukerb/.terraform.d/plugins/registry.terraform.io/hashicorp/restapi/1.20.0/linux_amd64/"
include = ["registry.terraform.io/*/*"]
}
direct {
exclude = ["registry.terraform.io/*/*"]
}
}
该路径存在,并且正是我之前提取的可执行文件所在的位置,但是当terraform init
在与 main.tf 相同的目录中执行时,我收到以下错误
Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/restiapi: provider registry.terraform.io/hashicorp/restiapi was not found in any of the search
│ locations
│
│ - /home/lukerb/.terraform.d/plugins/registry.terraform.io/hashicorp/restapi/1.20.0/linux_amd64/
╵
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/restapi: provider registry.terraform.io/hashicorp/restapi was not found in any of the search
│ locations
│
│ - /home/lukerb/.terraform.d/plugins/registry.terraform.io/hashicorp/restapi/1.20.0/linux_amd64/
我的 main.tf 包含
terraform {
required_providers {
restapi = {
source = "hashicorp/restapi"
version = "1.20.0"
}
}
}
我激活了详细日志来尝试了解问题所在,据我所知,当尝试初始化时,检查了位置但没有找到任何东西
[TRACE] Selected provider installation method cliconfig.ProviderInstallationFilesystemMirror("/home/lukerb/.terraform.d/plugins/registry.terraform.io/hashicorp/restapi/1.20.0/linux_amd64/") with includes [registry.terraform.io/*/*] and excludes []
[TRACE] Selected provider installation method cliconfig.ProviderInstallationDirect with includes [] and excludes [registry.terraform.io/*/*]
[INFO] CLI command args: []string{"init"}
Initializing the backend...
[TRACE] Meta.Backend: no config given or present on disk, so returning nil config
[TRACE] Meta.Backend: backend has not previously been initialized in this working directory
[TRACE] Meta.Backend: using default local state only (no backend configuration, and no existing initialized backend)
[TRACE] Meta.Backend: instantiated backend of type <nil>
[DEBUG] checking for provisioner in "."
[DEBUG] checking for provisioner in "/usr/bin"
[DEBUG] checking for provisioner in "/home/lukerb/.terraform.d/plugins"
有人知道我哪里犯了错误或者问题到底是什么吗?
编辑:
按照@Matthew Schuchard 的建议进行更改后,我收到了类似的错误
2025-04-08T15:33:07.564+0200 [INFO] Terraform version: 1.11.3
2025-04-08T15:33:07.564+0200 [DEBUG] using github.com/hashicorp/go-tfe v1.70.0
2025-04-08T15:33:07.564+0200 [DEBUG] using github.com/hashicorp/hcl/v2 v2.23.0
2025-04-08T15:33:07.564+0200 [DEBUG] using github.com/hashicorp/terraform-svchost v0.1.1
2025-04-08T15:33:07.564+0200 [DEBUG] using github.com/zclconf/go-cty v1.16.0
2025-04-08T15:33:07.564+0200 [INFO] Go runtime version: go1.23.3
2025-04-08T15:33:07.564+0200 [INFO] CLI args: []string{"terraform", "init"}
2025-04-08T15:33:07.564+0200 [TRACE] Stdout is a terminal of width 120
2025-04-08T15:33:07.564+0200 [TRACE] Stderr is a terminal of width 120
2025-04-08T15:33:07.564+0200 [TRACE] Stdin is a terminal
2025-04-08T15:33:07.564+0200 [DEBUG] Attempting to open CLI config file: /home/lukerb/.terraformrc
2025-04-08T15:33:07.564+0200 [INFO] Loading CLI configuration from /home/lukerb/.terraformrc
2025-04-08T15:33:07.564+0200 [DEBUG] checking for credentials in "/home/lukerb/.terraform.d/plugins"
2025-04-08T15:33:07.564+0200 [DEBUG] Explicit provider installation configuration is set
2025-04-08T15:33:07.564+0200 [TRACE] Selected provider installation method cliconfig.ProviderInstallationFilesystemMirror("/home/lukerb/.terraform.d/plugins/registry.terraform.io/Mastercard/restapi/1.20.0/linux_amd64") with includes [registry.terraform.io/*/*] and excludes []
2025-04-08T15:33:07.565+0200 [INFO] CLI command args: []string{"init"}
Initializing the backend...
2025-04-08T15:33:07.565+0200 [TRACE] Meta.Backend: no config given or present on disk, so returning nil config
2025-04-08T15:33:07.565+0200 [TRACE] Meta.Backend: backend has not previously been initialized in this working directory
2025-04-08T15:33:07.565+0200 [TRACE] Meta.Backend: using default local state only (no backend configuration, and no existing initialized backend)
2025-04-08T15:33:07.565+0200 [TRACE] Meta.Backend: instantiated backend of type <nil>
2025-04-08T15:33:07.565+0200 [DEBUG] checking for provisioner in "."
2025-04-08T15:33:07.567+0200 [DEBUG] checking for provisioner in "/usr/bin"
2025-04-08T15:33:07.568+0200 [DEBUG] checking for provisioner in "/home/lukerb/.terraform.d/plugins"
2025-04-08T15:33:07.568+0200 [TRACE] Meta.Backend: backend <nil> does not support operations, so wrapping it in a local backend
2025-04-08T15:33:07.568+0200 [TRACE] backend/local: state manager for workspace "default" will:
- read initial snapshot from terraform.tfstate
- write new snapshots to terraform.tfstate
- create any backup at terraform.tfstate.backup
2025-04-08T15:33:07.568+0200 [TRACE] statemgr.Filesystem: reading initial snapshot from terraform.tfstate
2025-04-08T15:33:07.568+0200 [TRACE] statemgr.Filesystem: snapshot file has nil snapshot, but that's okay
2025-04-08T15:33:07.568+0200 [TRACE] statemgr.Filesystem: read nil snapshot
Initializing provider plugins...
- Finding mastercard/restapi versions matching "1.20.0"...
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider mastercard/restapi: provider
│ registry.terraform.io/mastercard/restapi was not found in any of the search locations
│
│ - /home/lukerb/.terraform.d/plugins/registry.terraform.io/Mastercard/restapi/1.20.0/linux_amd64