中村的雑記

技術に関する記事を書いていきます。iOSエンジニア->Railsエンジニア。

Terraformのv0.14へのアップデートに関するエラー

はじめに

小ネタ。

勉強会でTerraformを使っていて、
v0.12 => v0.14にアップデートした後terraform applyをすると、
下記エラーに遭遇した。

- Finding hasicorp/aws versions matching “~> 3.0”...
Error: Failed to query available provider packages
Could not retrieve the list of available versions for provider hasicorp/aws:
provider registry registry.terraform.io does not have a provider named
registry.terraform.io/hasicorp/aws
If you have just upgraded directly from Terraform v0.12 to Terraform v0.14
then please upgrade to Terraform v0.13 first and follow the upgrade guide for
that release, which might help you address this problem.

要約するとv0.12 => v0.14にあげる時はv0.13に一回上げてくれ、とのことだ。
そして確認してくれ、と言われているガイドはこれ。↓

www.terraform.io

解決法

上記ガイドに、

In particular, Terraform v0.14 no longer includes the terraform 0.13upgrade command for automatically inserting provider requirements into existing modules, and the automatic mechanisms to upgrade legacy provider references in the Terraform state. You will need to successfully complete a terraform apply at least once under Terraform v0.13 before upgrading an existing configuration to Terraform v0.14.

と書いてあるので、下記の手順で対処をした。

  • tfenv install 0.13.6 でインストール
  • tfenv use 0.13.6 で切り替える
  • terraform applyを実行
  • tfenv use 0.14.5 で切り替える

ミソは、v0.13に切り替えた後、一度terraform apply しないと、上記エラーが解決しないというところ。

今回の記事は以上。