注:这是一个自我回答的问题,以帮助处于类似情况的任何人。
在将Terraform升级到0.15时,我们得到了以下错误消息(以及用于aws和random提供程序的类似消息):
> terraform -chdir=aws init --upgrade
Upgrading modules...
Downloading git@github.com:penngineering/ops-terraform-lambda.git?ref=tf-15 for stream_handler...
- stream_handler in .terraform/modules/stream_handler
Initializing the backend...
Successfully configured the backend "s3"! Terraform will automatically
use this backend unless the backend configuration changes.
╷
│ Error: Invalid legacy provider address
│
│ This configuration or its associated state refers to the unqualified provider "pagerduty".
│
│ You must complete the Terraform 0.13 upgrade process before upgrading to later versions.
╵
...但是,我们不使用pagerduty提供程序,根模块引用的任何模块也不使用。运行terraform providers将提供以下输出:
Providers required by configuration:
.
├── provider[registry.terraform.io/hashicorp/archive] 2.2.0
├── provider[registry.terraform.io/hashicorp/aws] 3.39.0
├── provider[registry.terraform.io/hashicorp/local] 2.1.0
├── provider[registry.terraform.io/hashicorp/null] 3.1.0
└── provider[registry.terraform.io/hashicorp/random] 3.1.0
Providers required by state:
provider[registry.terraform.io/hashicorp/aws]
provider[registry.terraform.io/hashicorp/local]
provider[registry.terraform.io/hashicorp/null]
provider[registry.terraform.io/hashicorp/random]
provider[terraform.io/builtin/terraform]
provider[registry.terraform.io/hashicorp/archive]下载外部状态并为提供程序加油显示了相同的提供程序列表。
打开日志没有帮助:我们可以看到Terraform在哪里调用检索远程状态,然后它打印错误消息并退出。没有迹象表明它正在做什么来试图找出提供程序配置。
谷歌没有出现太多;在大多数情况下,人们没有正确地完成0.13的升级。我们确实更新了提供程序名称与required_providers配置完全匹配的状态,如这个StackOverflow的答案所示,但这没有帮助。
发布于 2021-05-16 13:57:02
谷歌确实出现了这条线,这让我们找到了答案。
Terraform有“默认”工作区的概念,如果您运行terraform init而不指定工作区,它将基于此工作区进行初始化。但是,我们不使用默认工作区;我们的每个根模块都在一个显式工作区中。
我们的构建过程在plan和apply之前使用了D4。但是,在init之前,您不能以这种方式选择工作区。init使用的是默认工作区(我猜它在Terraform二进制文件中有一个实际的默认配置,用于初始化完全新的项目)。
解决方案是在运行TF_WORKSPACE环境变量时使用init (我们现在在任何地方都使用它):
TF_WORKSPACE=${WORKSPACE} terraform -chdir=${MODULE} init --upgrade https://serverfault.com/questions/1063726
复制相似问题