M1 Mac で terraform init の platform エラーにハマって m1-terraform-provider-helper に助けられた
とあるサーバを作りかけで忘れていた Terraform の作業を再開したところ、以下のエラーが出てハマり、 m1-terraform-provider-helper で解消したメモです。
Provider registry.terraform.io/hashicorp/template v2.2.0 does not have a package available for your current platform, darwin_arm64.
対策
私のケースでの解決方法は以下でした。
# m1-terraform-provider-helper をインストール
$ brew install kreuzwerker/taps/m1-terraform-provider-helper
# Platformエラーとして表示されている `hashicorp/template v2.2.0` をインストール
$ m1-terraform-provider-helper activate
$ m1-terraform-provider-helper install hashicorp/template -v v2.2.0
# ここまでで解決すれば良いが、以下も必要な場合がある(lockファイル内に情報が残っているため)
$ rm .terraform.lock.hcl
# このあとはいつものterraform init/plan/apply
m1-terraform-provider-helper は kreuzwerker 氏が開発し以下で公開されているものです。説明にある通りソースをDLして手元のM1環境でコンパイルすることで、M1 chipで使えるバイナリを生成するツールです。素晴らしいですし大変助かりました。1
CLI to support with downloading and compiling terraform providers for Mac with M1 chip GitHub - kreuzwerker/m1-terraform-provider-helper: CLI to support with downloading and compiling terraform providers for Mac with M1 chip · GitHub
環境
私の環境は以下です。
- Terraform v1.1.7
- Provider hashicorp/aws v4.3.0
- MacBook Pro (13-inch, M1, 2020)
- Version 11.6.4 (20G417)
実際のコマンドエラー結果
実際のコマンドを実行した時のエラー結果は以下の通りです。
$ terraform init
Initializing modules...
Initializing the backend...
Initializing provider plugins...
- terraform.io/builtin/terraform is built in to Terraform
- Reusing previous version of hashicorp/template from the dependency lock file
- Reusing previous version of hashicorp/aws from the dependency lock file
- Installing hashicorp/aws v4.3.0...
- Installed hashicorp/aws v4.3.0 (signed by HashiCorp)
╷
│ Error: Incompatible provider version
│
│ Provider registry.terraform.io/hashicorp/template v2.2.0 does not have a package available for your current platform,
│ darwin_arm64.
│
│ Provider releases are separate from Terraform CLI releases, so not all providers are available for all platforms. Other versions
│ of this provider may have different platforms supported.
╵
とりあえずエラーメッセージをDuckDuckGoで検索して同じような現象の方のブログに辿り着きました。インターネットは素晴らしい。
References
以下の記事でほぼ解決できました。ありがとうございます。 https://qiita.com/isosa_yama/items/8967a1bfbe2623d023d4
以下は作者の kreuzwerker さんが自身のブログで m1-terraform-provider-helper を紹介している記事です。2021-10-29 には作成されていたようです、ありがたい。 Secure Mobile Working Without A Designated IT Specialist - PCG
同じエラーで困っているHashicorp Discussのスレがあったので $ rm .terraform.lock.hcl してみたら?と助言してみました。
Template v2.2.0 does not have a package available - Mac M1 - #11 by rohitvit276 - Terraform Providers - HashiCorp Discuss
Goの互換性の高さにも感謝すべきなはず ↩︎