LoginSignup
0

More than 5 years have passed since last update.

terraform destroy で IAM Policy を削除するときは予めデタッチ

Posted at

※ 対象Ver: Terraform v0.8.8
 v0.9 以降は未確認。

TerraformでアタッチしたものであればDestroy処理の中でデタッチされるが、そうでないもの(Terraform管理外のアタッチ)は予めデタッチしておかないとエラーになる。
初期構築時にTerraformでポリシーを作り、運用でTerraformを使わずにアタッチしていた環境で、このケースにハマった。

そのときのメッセージは以下。

aws_iam_policy.xxxxxxxx: Destroying...
Error applying plan:

1 error(s) occurred:

* aws_iam_policy.xxxxxxxx: Error reading IAM policy 
arn:aws:iam::xxxxxxxx:policy/xxxxxxxx: 
&awserr.requestError{awsError:(*awserr.baseError)(0xc42064a840), 
statusCode:409, requestID:"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"}

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

エラーメッセージ内に Error reading IAM policy とあったのでTerraform実行IAMの権限の問題かと最初は考えたが、何度見直しても権限は足りている。
その場合、AccessDeny というメッセージが出るはずだし。

statusCode:409 で検索したら Conflict という言葉が出てきたので原因に気付くことができた。
わかりづらくないですか。

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
0