## TL;DR

The agent applied a generic old-version cleanup lifecycle to the Terraform state bucket, and the rule purged the state history that Terraform needs for recovery and locking. Remove the lifecycle rule from the state bucket immediately, verify current state integrity, and exclude state buckets from all automated lifecycle policies permanently. State history is not clutter; it is the recovery mechanism.

## Error

```text
agent set lifecycle rules on the terraform state bucket  -  state versions got purged
```

## Steps

1. Remove the lifecycle rule from the state bucket now. Expected: no further versions are purged.
2. Verify the current state file is intact and Terraform operations still work. Expected: plans and applies function normally.
3. Check whether needed historical versions are gone; restore from backup if the team keeps state backups. Expected: the recovery scope is known.
4. Tag the state bucket to exclude it from lifecycle automation, and add the exclusion to the agent's scope. Expected: the bucket is permanently out of scope.
5. Require human approval for lifecycle changes on any bucket holding infrastructure state. Expected: no automated lifecycle without review.

## When to use

- Lifecycle rules purge Terraform state versions.
- The state bucket is in an automation's scope.
- Protecting infrastructure-state storage.

## When not to use

- The lifecycle targets a different bucket (scope the rule correctly).
- State versioning was intentionally disabled (a team decision).
- The purge has not happened yet (remove the rule before it does).

## Tool compatibility

AWS S3 lifecycle, Terraform remote state (current 2026 releases).

### Variant phrasings

### lifecycle rule ate the tfstate history

Remove the rule and exclude state buckets.

### state versions purged by cleanup

Restore from backup; protect the bucket.

### generic cleanup hit the state bucket

Exclude infrastructure-state buckets from automation.

## Why it happens

Generic storage-cleanup rules treat all buckets alike: old versions look like waste everywhere. But Terraform state versions are the undo history for infrastructure; purging them removes the ability to recover from a bad apply. The bucket's purpose makes its versions load-bearing, which is why state storage must be categorically excluded from automated lifecycle, not just carefully included.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_CClk7N6D_HqSFlQg_Tq1gg
