A Confluent Terraform apply shortens retention and deletes records still in use
The scenario
Terraform apply sets a Confluent Cloud topic's retention lower so the module matches a default. Kafka starts deleting segments older than the new limit. A consumer that was down for the weekend still needs those records. Its offset is now past the start of the log, and the records are gone. The plan had no destroy line, so CI let it through.
Model answer
What I'd say first:
I would stop the apply from shortening retention on a topic someone still reads. Retention is how long records stay. Lowering it deletes old segments. There is no destroy line, and the data still disappears.
How I'd work it:
- 1Halt further applies. If the segments are already gone, do not pretend a re-apply will bring them back.
- 2Compare the oldest offset anyone still needs with the new retention. Confirm the weekend consumer's bookmark is now outside the log.
- 3Put retention back to a window that covers the slowest consumer, including a down weekend. If tiered copies of the deleted segments still exist, restore from those with a planned replay, not a second silent trim.
- 4Tell the room a retention change deleted live backlog. The module owner stays until retention covers every reader and CI fails a shorten that undercuts them.
How I'd explain it:
Kafka deletes segments that fall outside retention. Terraform calls that an in-place update, so a green plan can still drop records. A wrong answer is to say there was no destroy, so nothing important happened. The consumer's bookmark is the proof. It points at records that are no longer there.
How I'd prevent it:
A plan check that fails when retention shrinks below the oldest offset still needed. Retention set with the consumer SLO. An alert when the log start jumps ahead of commits.
The follow-up they'll ask
“Re-apply the Confluent module so retention stays short and the topic matches source control?”
No. I would not re-apply the short retention. Source control is wrong here, because the module default is shorter than the readers need. Kafka has already deleted segments, and another apply deletes more. I put retention back to cover the slowest consumer, including one that was down for the weekend. A plan with no destroy line can still drop records. The bookmark that now falls outside the log is the incident, and matching the module does not fix it.
Common mistakes
- Treat an in-place retention change as safe
- Re-apply the short default
- Ignore a consumer that was down
- Assume deleted segments come back on the next apply