1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

リソースを削除せずにTerraform管理外にできるremovedブロック

Last updated at Posted at 2025-06-09

概要

リソースを削除せずにTerraform管理外としたい場合に有効

似ているものでignoreがあるが、あれはtfstateとデプロイ済みリソースとの差分を特定の設定項目のみ無視する意味になるので、少し挙動が違う

でも、わかると便利

やり方

以下のようにresourceブロックを削除した上で、removedブロックを記述する

destroy = falseにすることで物理削除はされなくなる

- # resourceブロックは削除する
- resource "aws_s3_bucket" "hoge-s3-bucket" {
-   bucket = "hoge-test-s3-bucket"
- }

+ removed {
+   from = aws_s3_bucket.hoge-s3-bucket
+   lifecycle {
+     # falseするとリソースが削除されなくなる (デフォルトはtrueなので注意)
+     destroy = false
+   }
+ }

対象resourceブロックを削除しておかないと以下のようなエラーになるので注意してください。


This statement declares that aws_s3_bucket.hoge-s3-bucket was removed, but it is still declared in configuration.
1
0
0

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?