3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

terraform update後の「Error: Invalid legacy provider address」に対処する

Posted at

1. はじめに

今回terraform version 0.12で作成されたtfstateをメンテした際に遭遇したエラーで、ターミナルの指示通りにterraform init -migrate-stateterraform init -reconfigureしても動作しませんでした。

エラーでググると「providersの/-/awsをreplaceすれば直るよ」みたいな記事は多かったのですが、自分の場合はtemplateも対象だったので一応書いておきます。

記事の時点ではTerraform v1.1.0です。

2. init出来ない状況確認

$ 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]

3. 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.
3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?