継続は力なり

タイトル通り定期的な更新を心掛けるブログです。

Terraform AWS Provider で初めて Provider がクラッシュする事態に遭遇した時の対処をまとめる

タダです.

Terraform AWS Provider の 5.3.0,5.4.0 で OpenSearch Serverless のリソースが対応するようになりました.そこでリソースを作ってみた後, terraform plan を実行した時に Error: The terraform-provider-aws_v5.4.0_x5 plugin crashed! とメッセージが出力されて実行計画ができなくなりました.この記事ではその際にどのように対処したかを備忘録としてまとめます.

github.com

github.com

issue を立ててデバッグログを確認した

まず,クラッシュ時のメッセージの中にあるように issue を起票しました.そして,issue 内でデバッグログの取得と提供を依頼されたのでデバッグログを取るようにして,実行計画を再度試してみました.

クラッシュ時のメッセージ抜粋

Error: The terraform-provider-aws_v5.4.0_x5 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely helpful if you could report the crash with the plugin's maintainers so that it can be fixed. The output above should help diagnose the issue.

デバッグログ取得の設定例

export TF_LOG=DEBUG
export TF_LOG_PATH=./terraform-debug.log

Terraform has detailed logs that you can enable by setting the TF_LOG environment variable to any value. Enabling this setting causes detailed logs to appear on stderr.

You can set TF_LOG to one of the log levels (in order of decreasing verbosity) TRACE, DEBUG, INFO, WARN or ERROR to change the verbosity of the logs.

関連情報

developer.hashicorp.com

developer.hashicorp.com

デバッグログの中身から権限エラーを発見する

デバッグログの中を辿っていった時に exit status 2 直前のメッセージに aoss:BatchGetCollection アクションの権限エラーが発生している箇所を見つけました.確かに実行計画用の IAM には権限が不足していました.

HTTP Response Received: tf_rpc=ReadResource aws.operation=BatchGetCollection aws.service=OpenSearchServerless http.response.body="{"__type":"com.amazon.coral.service#AccessDeniedException","Message":"User: arn:aws:sts::1234567891911:assumed-role/hoge is not authorized to perform: aoss:BatchGetCollection on resource: arn:aws:aoss:ap-northeast-1:1234567891911:collection/xxx because no identity-based policy allows the aoss:BatchGetCollection action"}

そこで,実行計画用の IAM に権限を付けて再度実行計画を試してみたところクラッシュせずに処理が完了しました.ログの中身を確認することって改めて大事ですね.

まとめ

Terraform AWS Provider を 5.4.0 に変更後に Provider がクラッシュした際の対処と解決策をまとめました.最初メッセージを見た時は何が何だかわからなかったですが,デバッグログの中身から解決できたので,今後はログの中身を辿ってから解決できないか試してみようと思いました.