【问题标题】:Why doesn't Terraform see my manually installed provider?为什么 Terraform 看不到我手动安装的提供程序?
【发布时间】:2020-08-19 09:00:57
【问题描述】:

我正在尝试将RKE provider 安装为Rancher AWS quickstart 的一部分。 Terraform documentation 表示插件应该安装在~/.terraform.d/plugins。 RKE 文档说插件应该安装在~/terraform.d/plugins/<your_platform>

为了协调相互冲突的信息,我尝试将二进制文件复制到以下所有位置,但 Terraform 从未见过它们中的任何一个:

~/.terraform.d/plugins/terraform-provider-rke
~/.terraform.d/plugins/rke
~/.terraform.d/plugins/darwin_amd64/terraform-provider-rke
~/.terraform.d/plugins/darwin_amd64/rke
~/terraform.d/plugins/terraform-provider-rke
~/terraform.d/plugins/rke
~/terraform.d/plugins/darwin_amd64/terraform-provider-rke
~/terraform.d/plugins/darwin_amd64/rke

在每种情况下,当我运行 terraform init 时,我都会收到以下错误:

Provider "rke" not available for installation.

A provider named "rke" could not be found in the Terraform Registry.

This may result from mistyping the provider name, or the given provider may
be a third-party provider that cannot be installed automatically.

In the latter case, the plugin must be installed manually by locating and
downloading a suitable distribution package and placing the plugin's executable
file in the following directory:
    terraform.d/plugins/darwin_amd64

Terraform detects necessary plugins by inspecting the configuration and state.
To view the provider versions requested by each module, run
"terraform providers".


Error: no provider exists with the given name

作为最后的手段,我可​​以使用terraform init -plugin-dir=<something>。但是随后 Terraform 没有看到任何自动下载的插件,我必须手动安装所有内容。

是否缺少一些路径变量,或者我未能遵循的其他命名约定?

【问题讨论】:

  • 为什么会改变结果?
  • 您自己构建它,如果您的环境有任何问题,它可能会以这种方式显示
  • 我自己构建了它并没有解决问题,但这帮助我缩小了范围,这让我能够弄清楚(见我的答案)。谢谢!

标签: terraform rancher rke


【解决方案1】:

事实证明,错误消息并没有说明全部情况。 Terraform 正在寻找提供者,但它认为它的版本不够新。

根据Terraform's documentation,提供者需要命名为terraform-provider-<NAME>_vX.Y.Zdocumentation for the RKE provider 表示该文件应称为terraform-provider-rke(无版本号)。

comment in the Terraform source code for plugin discovery 中,它表示支持这种无版本格式以实现反向兼容性。但是,Terraform 将版本解释为 v0.0.0

当我在失败的terraform init 之后运行terraform plan 时,它给了我一个信息更丰富的错误消息:

Error: provider.rke: no suitable version installed
  version requirements: "0.14.1"
  versions installed: "0.0.0"

该版本可能是另一个依赖于 RKE 提供者的提供者的要求。

我返回并从 Github 存储库手动下载了该版本,并将其复制到名为 terraform-provider-rke_v0.14.1 的插件目录中。成功了!

所以你去。如有疑问,请查看源代码。现在向 Rancher 提交问题报告,告诉他们更新他们的文档。 :-)

【讨论】:

    【解决方案2】:

    对于企业防火墙上的 Windows 用户,不允许直接下载提供商 zip 文件。

    1. 只需访问相应的 URL 即可下载提供商 ZIP 文件。

    • 现在,在根目录 - main.tf 文件中包含提供程序部分。
    1. 创建像 registry.terraform.io\hashicorp\aws\3.37.0\windows_amd64 这样的文件夹结构,并将从上面的 zip 中提取的 exe 文件放在这个位置。
    2. 进入命令行并运行:

    terraform init -plugin-dir .


    目录结构:

    • main.tf
    • registry.terraform.io\hashicorp\aws\3.37.0\windows_amd64\terraform_provider_aws_v3.37.0_x5.exe

    aws_v3.37.0_x5.exe

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-24
      • 2012-06-05
      • 2023-01-24
      • 1970-01-01
      • 2021-12-30
      • 1970-01-01
      • 1970-01-01
      • 2022-07-04
      相关资源
      最近更新 更多