Q: In Terraform, you have accidentally deleted an RDS instance definition from your `main.tf` file and hit `apply`. Terraform is now attempting to destroy the production database. How do you architect Terraform files to protect against catastrophic accidental deletions?
While strict code reviews and IAM Deny policies are essential, Terraform has an explicit safety net for this exact scenario.
Want to master this scenario in a live sandbox? The Linux Foundation's Certified System Administrator (LFCS) & SRE Track covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: "Senior DevOps is about building reliable automated feedback loops between code commit and production observability. The interviewer is testing: Terraform lifecycle rules, Prevent Destroy.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third."
Production Solution & Architecture
While strict code reviews and IAM Deny policies are essential, Terraform has an explicit safety net for this exact scenario. You should use the Terraform lifecycle block on any stateful, catastrophic-to-lose resources (like RDS, S3 buckets, DynamoDB tables). If a developer deletes this block or attempts to run terraform destroy, Terraform will parse the state file, observe the prevent_destroy metadata still attached to that resource, and flat-out refuse to execute the plan, throwing an error and saving the database.
resource "aws_db_instance" "production" {
# ... configuration ...
lifecycle {
prevent_destroy = true
}
}
- Immediate Triage: While strict code reviews and IAM Deny policies are essential, Terraform has an explicit safety
- Run targeted verification commands before modifying configuration.
- Automate permanent guardrails (CI check, alerts, IaC policy) to prevent recurrence.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Engineering bespoke in-house developer tools instead of adopting standardized platform Golden Paths when configuring General Terraform accidentally Bespoke internal tools create long-term maintenance debt and fragmented workflows, whereas standardized Golden Paths accelerate delivery.
- Overlooking infrastructure cost visibility and FinOps allocation tagging across multi-tenant environments when configuring General Terraform accidentally Without granular resource tagging, engineering organizations cannot attribute cloud infrastructure costs to specific teams or business units.
- Failing to define explicit Service Level Objectives (SLOs) and Error Budgets to balance feature velocity with reliability when configuring General Terraform accidentally Without agreed SLOs, engineering and product teams lack an objective data-driven framework to prioritize technical debt over new features.
- Neglecting automated continuous drift detection between declarative configuration and deployed cloud state when configuring General Terraform accidentally Unmanaged drift accumulates over time, causing future automated deployments to fail or overwrite emergency manual adjustments.