Two repos accidentally manage the same S3 bucket. What happens, and how do you resolve it?
AdvancedScenarioState Backends and Workspaces
Answer
Situation read → Dual ownership: each state thinks it owns the resource, and they fight.
What I'd do →
- Decide the owner, ideally the team that owns the lifecycle.
- In the other repo, add a
removedblock withdestroy = false(orstate rm) and apply. - Consumers of the bucket use a data source instead.
- Add CODEOWNERS or tagging (
ManagedBy,Stack) to make ownership visible.
Why → Two states reconciling one resource produce perpetual diffs, and a destroy in either repo deletes it for both.
Interview tip → Ownership should be answerable from a tag.
More on State Backends and Workspaces
Two engineers keep overwriting each other's changes because state is local. What's the fix?BeginnerSet up a production-grade S3 backend. What do you configure for locking?IntermediateHow do you harden the S3 bucket that holds Terraform state?IntermediateWho creates the state bucket itself, given Terraform needs it to exist before `init`?IntermediateA laptop apply and a CI apply start at the same time. What stops state corruption?IntermediateWhen are Terraform workspaces appropriate?Beginner