AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / coding / 问题 / 79561945
Accepted
Elarbe
Elarbe
Asked: 2025-04-08 19:56:44 +0800 CST2025-04-08 19:56:44 +0800 CST 2025-04-08 19:56:44 +0800 CST

在 filesystem_mirror 位置未找到 Terraform v1.11.3 提供程序

  • 772

我正在尝试安装这个“愚蠢的”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
terraform
  • 2 2 个回答
  • 41 Views

2 个回答

  • Voted
  1. Matthew Schuchard
    2025-04-08T21:20:45+08:002025-04-08T21:20:45+08:00

    插件的命名空间不正确。组织是Mastercard而不是hashicorp。您需要在配置中进行更新:

    terraform {
      required_providers {
        restapi = {
          source = "Mastercard/restapi"
          version = "1.20.0"
        }
      }
    }
    

    以及您的目录结构:

    filesystem_mirror {
      path    = "/home/lukerb/.terraform.d/plugins/registry.terraform.io/Mastercard/restapi/1.20.0/linux_amd64/"
      include = ["registry.terraform.io/*/*"]
    }
    

    请注意,文件系统上的插件位置也需要固定以匹配上述路径。

    • 2
  2. Best Answer
    Martin Atkins
    2025-04-09T06:10:04+08:002025-04-09T06:10:04+08:00

    文件系统镜像路径必须位于镜像的根目录下,位于代表镜像中包含的各个提供程序的路径段之前。

    例如:

    provider_installation {
      filesystem_mirror {
        path    = "/home/lukerb/.terraform.d/plugins"
        include = ["registry.terraform.io/*/*"]
      }
      direct {
        exclude = ["registry.terraform.io/*/*"]
      }
    }
    

    然后,Terraform 在给定的目录下进行搜索,以找出其中包含的特定提供程序。


    请注意,您在此处指定的目录(假设这是您的主目录)是Terraform 使用隐含镜像目录模式/home/lukerb时自动搜索的位置之一。

    因此,您可以删除整个provider_installation代码块以激活 Terraform 的默认隐式行为。在这种情况下,Terraform 将搜索该目录以找出其中包含的提供程序,并构建一个隐式配置,该配置仅从本地镜像安装这些特定的提供程序,同时从注册表安装所有其他提供程序。

    例如,如果该提供程序是镜像目录中唯一的提供程序,那么 Terraform 将为自己构建一个相当于这样的配置:

    provider_installation {
      filesystem_mirror {
        path    = "/home/lukerb/.terraform.d/plugins"
        include = ["registry.terraform.io/hashicorp/restapi"]
      }
      direct {
        exclude = ["registry.terraform.io/hashicorp/restapi"]
      }
    }
    

    请注意,此自动推断的配置仅从本地目录安装特定的提供程序,同时允许其他所有内容仍从公共注册表安装。


    最后,提供商源地址的“命名空间”部分registry.terraform.io对应于 GitHub 组织名称或用户名,因此“hashicorp”并非此处应使用的正确名称。Terraform 本身当然不知道这一点,因此无需进行此操作即可使其正常工作,但我建议更正此问题,以帮助系统的未来维护者了解此提供商的来源。

    • 在您的镜像目录中,将提供程序安装在 下,registry.terraform.io/mastercard/restapi而不是 下registry.terraform.io/hashicorp/restapi。
    • 在 Terraform 模块的required_providers块中,指定source = "mastercard/restapi而不是source = "hashicorp/restapi"。

    我注意到,如果您使用正确的源地址,此提供程序在 Terraform Registry 中可用:。因此,如果您在配置中指定了正确的源地址,而不是错误地将其指定为属于命名空间,则可能完全mastercard/restapi可以跳过使用本地镜像目录。hashicorp

    • 1

相关问题

  • 在 Terraform 中动态生成 JSON

  • 如果 Terraform 不存在,则创建用户

  • Terraform:从列表指定的地图中复制特定元素

  • Terraform 模板不会按值替换变量

  • 无法从 ALB 模块的多个 ID 中检索单个 EC2 实例 ID

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve