Q: What is `terraform taint` and when would you use it?
terraform taint <resource> marks a resource for destruction and recreation on the next terraform apply. Even if nothing in the config cha...
#Terraform #Modules & Structure #L2 #IaC #Cloud Infrastructure #EC2
🎙️ Candidate Opening & Architectural Context
""Managing infrastructure as code across multiple teams requires disciplined state management and locking. When addressing this question, I walk the interviewer through our production incident runbook: isolating the blast radius, checking diagnostic logs and metrics, and applying a safe fix.""
Advertisement
🛠️ Production Runbook & Step-by-Step Resolution
1️⃣
Initial Diagnostics & Root Cause Analysis
terraform taint marks a resource for destruction and recreation on the next terraform apply. Even if nothing in the config changed.
- A resource is in a broken/inconsistent state in the cloud but Terraform's state says it's fine.
- You want to force recreation of an EC2 instance to apply a new AMI (for resources that can't be updated in-place).
2️⃣
Remediation & Permanent Safeguards
Use cases: In Terraform 0.15.2+, terraform taint is replaced by terraform apply -replace= which is more explicit. Note: tainting deletes and recreates. For stateful resources (databases, volumes), this means data loss. Be careful.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: A resource is in a broken/inconsistent state in the cloud but Terraform's state says it's fine.."
⚡ 60-Second Elevator Pitch Talking Points
- A resource is in a broken/inconsistent state in the cloud but Terraform's state says it's fine.
- You want to force recreation of an EC2 instance to apply a new AMI (for resources that can't be u...
Advertisement