v0.13が出てからしばらく経ちましたが、何気にv0.12アップグレード時よりエラーがよく出たので、まとめておこうと思います。
アップグレードの方法に関しては公式サイトでまとまっています。
https://www.terraform.io/upgrade-guides/0-13.html
内容を読むとプロバイダーの明示的な指定だったりと、そこまで破壊的じゃなさそうだったので、
エラーが出てもその場で修正という形をとろうと、えいやで変更したら痛い目を見ました。
Error: Failed to decode current backend config
Error: Failed to decode current backend config
The backend configuration created by the most recent run of "terraform init"
could not be decoded: unsupported attribute "lock_table". The configuration
may have been initialized by an earlier version that used an incompatible
configuration structure. Run "terraform init -reconfigure" to force
re-initialization of the backend.
.terraform/terraform.tfstate
ここにtfstateの保存場所の情報、つまりbackendの情報が載ってますが、
terraform v0.13ではいくつか廃止された属性がある模様です。
- lock_table
- skip_get_ec2_platforms
- skip_requesting_account_id
これらの行を消してやれば動きます。
でもわざわざテキストエディタを開いて消さずとも
$ terraform init -reconfigure
これで大丈夫なようです。
Error: Could not load plugin
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/aws" to
obtain schema: unknown provider "registry.terraform.io/hashicorp/aws"
- Failed to instantiate provider "registry.terraform.io/-/aws" to obtain
schema: unknown provider "registry.terraform.io/-/aws"
プラグインのパスが変わって、 .terraform/plugins/registry.terraform.io/
の中にプラグインの情報がないので
$ terraform init
すれば大丈夫ですが、reconfigureと合わせてやってしまったほうが手っ取り早いです。
Error: Could not load plugin (2回目)
$ 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".
Failed to instantiate provider "registry.terraform.io/-/aws" to obtain schema:
Unrecognized remote plugin message:
This usually means that the plugin is either invalid or simply
needs to be recompiled to support the latest protocol.
Errorとしては先ほどと同じで、プラグインもロードできているのになぜか同じエラーが出ました。
結果的にはterraform_remote_stateを利用しており、利用先のtfstateが新しくなっていないとエラーが出るようでした。
そのため参照先のリソース群をterraform init -reconfigure
することで解消しました。
Error: Invalid index
こちらに詳しく書きました。
どちらかというと、providerの問題です。
v0.13対応のプラグインを利用すると、古いプラグインと仕様が少し異なることがあります。
そのためいくつか差分が発生する可能性があります。
これもその手の話です。
- for_each + state mvで対処する
- tolistで対処する
どちらかで対処します。
Error: GET https://example.jp/api/v3/api/v3/repos/example-org/example-repo: 404 Not Found []
GitHubのProviderを利用している箇所で発生しました。
GitHub EnterpriseをEC2でホストしている箇所です。
- base_url = "https://example.com/api/v3/"
+ base_url = "https://example.com/"
token = data.aws_ssm_parameter.apikey.value
insecure = true
organization = "example-org"
base_urlの仕様が変わってるようでした。
GitHub Enterpriseを利用している際、わざわざapiのパスをつけなくてもよくなったようです。
これもv0.13の問題かというとちょっと微妙でプロバイダーのバージョンの問題のようです。
Error: Invalid resource instance data in state
Error: Invalid resource instance data in state
on aws_efs.tf line 1:
1: resource "aws_efs_file_system" "efs" {
Instance aws_efs_file_system.efs data could not be decoded from the
state: unsupported attribute "reference_name".
Error: Invalid resource instance data in state
on aws_efs.tf line 1:
これもaws providerのバージョンの問題です。
新しいバージョンでは出力されている属性がサポートされていないようです。
バージョンをこまめに上げていれば、こんなことは起きなかったかもしれませんが、起きてしまったので対処します。
手段は以下になるかなと思います。他にも方法はあるかもしれません。
- tfstateを書き換える
- state rm + importを行う
前者はやりたくないので、後者をとりました。
まとめ
他の方のまとめを読んでいると、tfstate書き換えたり、.terraform/を削除したりしていることが多いように感じました。
情報が多少重複しているかもしれませんが、ほかの手段もある、ということでまとめてみました。
まだ完全に終わっていないため、まだ出てくるかもしれませんが、その際は追記していこうと思います。