Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
terraform destroyでdevのリソースが被弾した話
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
うな
August 11, 2026
65
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
terraform destroyでdevのリソースが被弾した話
うな
August 11, 2026
More Decks by うな
See All by うな
本番環境だけ動かない不具合を追いかけたら、AWS WAFに行きついた話
yunauna_u7
0
84
Featured
See All Featured
Un-Boring Meetings
codingconduct
0
440
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
550
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
350
brightonSEO & MeasureFest 2025 - Winning Strategies for Black Friday CRO & PPC - Christian Goodrich
cargoodrich
3
860
It's Worth the Effort
3n
188
29k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
The Curse of the Amulet
leimatthew05
3
15k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
42k
First, design no harm
axbom
PRO
2
1.3k
Deep Space Network (abreviated)
tonyrice
0
360
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.7k
Transcript
2026/08/06 terraform destroy で dev のリソースが被弾した話 うな(内山 優布奈)
1. プロフィール うな (内山 優布奈) 社会人 2 年目 / •
農学部出身 • 趣味:ライブ AWS 歴 9 ヶ月
2. インシデント全体像 destroy 前 destroy 後 STG STG CloudFront RDS
EC2 RDS EC2 RDS EC2 DEV DEV CloudFront CloudFront RDS EC2 CloudFront
3. 原因① state ファイルの共有 Terraform は state でリソースを管理する terraform.tfstate(単一ファイル) stg
apply → state に書き込み Dev CloudFront Dev RDS Dev EC2 ここが問題 dev apply → 同じ state 書き込み var-file で 絞れると思った STG RDS STG ... destroy は state の中身を全部対象にする
4. 原因① var-file ≠ state の分離 -var-file は「state の参照先」を変えない terraform.tfstate
今何が管理されているか -var-file コードをどう評価するか terraform.tfvars environment = "stg" コードの評価値を変える (変数の値だけ) 独立!! Dev CloudFront Dev RDS Dev EC2 STG RDS STG ... destroy の対象 = state 全体 state を分離しなければ、環境は分離されない
5. 原因② count パターンの罠 environment = "stg" で実行すると ... cloudfront.tf
count = "stg" == "dev" = false ? 1 : 0 = 0 ? 1 : 0 count による環境切り替えパターン count = 1 リソースが存在する count = 0 リソースが存在すべきでない = 削除 count で環境を切り替えるのは危険
6. なぜ CloudFront だけ消えたか var.environment = "stg" で destroy したとき
リソース count 条件 count 値 結果 Dev CloudFront env == "dev" ? 1 : 0 0 消えた STG CloudFront env == "stg" ? 1 : 0 1 意図通り削除 RDS なし(常に存在) — 生き残り EC2 なし(常に存在) — 生き残り count = 0 は Terraform にとって 「このリソースは存在すべきでない」を意味する
7. 再発防止策 未実施 環境を分離するには state を分離する ① ディレクトリ分離(最推奨) ② Remote
State (S3 + DynamoDB) ③ Terraform Workspaces 本番運用・チーム開発向け 既存構成への暫定対処 どの方法でも「state の分離」が本質。 var-file の切り替えでは不十分
8. まとめ 1 -var-file は環境を分離しない 2 count による環境切り替えは危険 3 AI
のアドバイスは state 管理まで考慮しない Terraform は state で動く state を分離しなければ、環境も分離されない
ご清聴ありがとうございました