从 0.12 升级到 0.13:无法实例化提供程序“registry.terraform.io/-/aws”以获取

all*_*mon 9 terraform terraform-provider-aws

我正在尝试从 terraform 0.12 升级到 0.13。

当我运行时,它似乎没有任何特定的语法问题terraform 0.13upgrade

version.tf添加了一个文件

+terraform {
+  required_providers {
+    aws = {
+      source = "hashicorp/aws"
+    }
+  }
+  required_version = ">= 0.13"
+}
Run Code Online (Sandbox Code Playgroud)

当我跑步时,terraform plan我得到了


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/-/aws" to obtain
schema: unknown provider "registry.terraform.io/-/aws"
- Failed to instantiate provider "registry.terraform.io/-/template" to obtain
schema: unknown provider "registry.terraform.io/-/template"

Run Code Online (Sandbox Code Playgroud)

跑步terraform providers节目

Providers required by configuration:
.
??? provider[registry.terraform.io/hashicorp/aws]
??? module.bastion
?   ??? provider[registry.terraform.io/hashicorp/template]
?   ??? provider[registry.terraform.io/hashicorp/aws]
??? module.vpc
    ??? provider[registry.terraform.io/hashicorp/aws] >= 2.68.*

Providers required by state:

    provider[registry.terraform.io/-/aws]

    provider[registry.terraform.io/-/template]

Run Code Online (Sandbox Code Playgroud)

所以我的猜测是出于某种原因,-/aws而不是hashicorp/aws在我的 tfstate 中,但是我在 tfstate 中根本找不到这个特定的字符串。

我试过:

  • 跑步 terraform init
  • terraform init -reconfigure
  • 删除.terraform文件夹
  • 删除~/.terraform.d文件夹

所以我没有关于如何解决这个问题的想法

all*_*mon 16

我按照这里的步骤

terraform state replace-provider   registry.terraform.io/-/template  registry.terraform.io/hashicorp/template
terraform state replace-provider   registry.terraform.io/-/aws  registry.terraform.io/hashicorp/aws
Run Code Online (Sandbox Code Playgroud)

它解决了我的问题。