The nightly `terraform plan` in CI says "# aws_db_instance.main must be replaced" after a provider upgrade, and auto-apply is enabled.
Likely causes → A change to a field that forces replacement: a provider default changed, someone edited the DB outside Terraform, a module input like identifier, engine or storage_encrypted changed, or a computed value now differs. Replace means destroy then create: an empty database.
Diagnose →
terraform plan -out=tfplan
terraform show -json tfplan | jq '.resource_changes[] | select(.change.actions|index("delete")) | {address, reason: .action_reason, paths: .change.replace_paths}'
The plan output marks the attribute with # forces replacement.
Fix → Stop auto-apply immediately. Pin the previous provider version, or make config match reality (set the attribute explicitly, or ignore_changes it if it's managed elsewhere).
Prevent → lifecycle { prevent_destroy = true } on stateful resources, deletion_protection = true on RDS, a CI policy (OPA/conftest on the plan JSON) that blocks any plan deleting databases or buckets, and human approval for production applies.