处理terraform update后的”Error: Invalid legacy provider address”错误

首先

在维护由Terraform版本0.12创建的tfstate时遇到了一个错误,尽管按照终端的指示进行了terraform init -migrate-state和terraform init -reconfigure,但仍无法正常工作。

在中文中重新表述以下内容,只需要一种选项:

当我在搜索错误时,我找到了很多类似的文章,说要”更换providers/-/aws”就可以解决了。但是对于我的情况,模板也是需要考虑的,所以我还是写下来。

目前的文章是指Terraform目前的版本是v1.1.0。

确认无法进行初始化的情况。

$ terraform init -reconfigure

 Error: Invalid legacy provider address

 This configuration or its associated state refers to the unqualified provider "aws". 

 You must complete the Terraform 0.13 upgrade process before upgrading to later       
 versions.
$ terraform providers

Providers required by configuration:
.
# ~省略~

Providers required by state:

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

使用terraform state replace-provider对其进行修复

# terraform providersにregistry.terraform.io/-/awsがあったら
$ terraform state replace-provider registry.terraform.io/-/aws registry.terraform.io/hashicorp/aws

# terraform providersにregistry.terraform.io/-/templateがあったら
$ terraform state replace-provider registry.terraform.io/-/template registry.terraform.io/hashicorp/template

4. 确认动作

$ terraform init

Initializing modules...

Initializing the backend...

Initializing provider plugins...
- Reusing previous version of hashicorp/aws from the dependency lock file
- Reusing previous version of hashicorp/template from the dependency lock file
- Using previously-installed hashicorp/aws v3.72.0
- Using previously-installed hashicorp/template v2.2.0

# ~省略~

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.

If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other        
commands will detect it and remind you to do so if necessary.
广告
将在 10 秒后关闭
bannerAds