【问题标题】:Terraform 'Failed to instantiate provider' for GCP error on Mac OS X对于 Mac OS X 上的 GCP 错误,Terraform“无法实例化提供程序”
【发布时间】:2021-06-16 01:24:29
【问题描述】:

昨天,Terraform 在我的 Mac OS X 笔记本电脑上运行良好。今天我开始使用它,我遇到了一个我以前从未见过的错误。我正在使用谷歌云提供商。

我运行 terraform init 并没问题,但是当我运行 terraform apply 时,我收到一条错误消息,上面写着 Failed to instantiate provider

terraform apply                                                        

Error: Could not load plugin


Plugin reinitialization required. Please run "terraform init".

Plugins are external binaries that Terraform uses to access and manipulate
resources. The configuration provided requires plugins which can't be located,
don't satisfy the version constraints, or are otherwise incompatible.

Terraform automatically discovers provider requirements from your
configuration, including providers used in child modules. To see the
requirements and constraints, run "terraform providers".

2 problems:

- Failed to instantiate provider "registry.terraform.io/hashicorp/google" to
obtain schema: fork/exec
.terraform/providers/registry.terraform.io/hashicorp/google/3.60.0/darwin_amd64/terraform-provider-google_v3.60.0_x5:
input/output error
- Failed to instantiate provider "registry.terraform.io/hashicorp/random" to
obtain schema: fork/exec
.terraform/providers/registry.terraform.io/hashicorp/random/3.1.0/darwin_amd64/terraform-provider-random_v3.1.0_x5:
input/output error

它告诉我运行terraform init 但是我已经这样做了。我一直在谷歌搜索,但没有运气。有谁知道如何解决这个错误?

【问题讨论】:

  • 您能否为 ypur 提供商发布内容?使用 terraform 版本?我可以尝试复制它并提供帮助。
  • 嗨,我在 terraform 0.14.8 上,我的提供者是 google:3.60.0,随机提供者是 3.1.0。如何为提供商提供内容?
  • 您是否尝试过删除 .terraform 文件夹及其所有内容,然后再次运行“干净”terraform init
  • @TimDunphy 您可以编辑您的原始帖子并添加提供者 sn-ps。
  • 是的,我已尝试删除 .terraform 文件夹并再次运行 terraform init。那没有效果。

标签: terraform terraform-provider-gcp


【解决方案1】:

原因

以 registry.terraform.io/-/ 开头的提供程序源地址是 Terraform 标记真实命名空间未知的遗留地址的一种特殊方式。对于在 Terraform 0.12 中自动安装的提供程序,Terraform 0.13 可以使用公共 Terraform 注册表中的查找表自动确定这些提供程序的新地址,但对于内部提供程序,您需要手动提供适当的映射(这可能是由于通过升级您的 terraform 版本)。

terraform state replace-provider 子命令允许重新分配记录在 Terraform 状态中的提供程序源地址,因此我们可以使用此命令告诉 Terraform 如何将“旧”提供程序地址重新解释为与配置中的提供者源地址。

解决方案

当使用带有默认本地后端的 Terraform CLI 时,可以通过使用以下步骤替换状态中的提供程序来解决错误。

如果状态文件存储在本地以外的后端,则必须先配置后端,然后才能运行相应的命令。如果状态文件存储在本地,则可以跳过此步骤。

如果需要,我们会提供配置后端的指南。请注意,执行此任务时,无需将工作空间中的 Terraform 配置文件下载到本地目录中。配置远程后端后,以下步骤将替换状态文件中的提供程序。

首先,初始化 Terraform。

$terraform init

一旦 Terraform 被初始化,以下语法可用于替换状态文件中的提供程序。系统将要求您确认更改,只有在回答“是”时才会继续。

$terraform state replace-provider registry.terraform.io/-/google 
registry.terraform.io/hashicorp/google

命令运行后,通过导航到 Terraform Enterprise 或 Terraform Cloud UI 上的工作区,单击“状态”并检查“几秒钟前”创建的最新版本,验证是否创建了新版本的状态。

有关如何将 CLI 与 Terraform Cloud 结合使用以及如何解决此问题的综合指南,您可以访问此页面 https://registry.terraform.io/providers/hashicorp/google/latest/docs/guides/version_3_upgrade#provider

【讨论】:

    【解决方案2】:

    我将 .terraform 文件夹重命名为其他内容,然后再次运行 tf init,然后运行 ​​tf plan,它运行良好。 早些时候它指向现有的插件,由于某种原因它们没有被正确引用。

    因此,您在代码中拥有的任何提供程序,您都可以通过从头开始来简单地获取它们。删除旧插件并以tf init开头

    【讨论】:

      猜你喜欢
      • 2020-06-12
      • 1970-01-01
      • 2020-02-11
      • 2020-01-17
      • 2018-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多