Resources are shared between two environments, such as a DNS zone. How do you avoid accidental deletion by either stack?
AdvancedScenarioImport Refactoring Drift and Lifecycle
Answer
Situation read → Shared dependency owned by neither environment.
What I'd do →
- Put shared resources in their own stack (
foundation/dns) with its own state and owner. - Environment stacks reference them with data sources.
- Add
prevent_destroyand service-level deletion protection where available.
Why → Resources that outlive environments belong to a lifecycle of their own.
Interview tip → "Lifecycle boundaries define state boundaries."
More on Import Refactoring Drift and Lifecycle
An S3 bucket was created by hand in the console and now must be managed by Terraform. How do you bring it in?BeginnerYou must adopt 200 existing resources and don't want to write all the HCL by hand.IntermediateHow do you find out that someone changed infrastructure outside Terraform?BeginnerSomeone opened port 22 on a security group in the console. Terraform wants to remove it. What's your process?IntermediateAn Auto Scaling group's desired capacity is changed by autoscaling, and Terraform keeps resetting it.IntermediateHow do you protect a production database from an accidental `terraform destroy`?Beginner