cloudposse / terraform-aws-tfstate-backend

Terraform module that provision an S3 bucket to store the `terraform.tfstate` file and a DynamoDB table to lock the state file to prevent concurrent modifications and state corruption.
https://cloudposse.com/accelerate
Apache License 2.0
408 stars 177 forks source link

Add lifecycle configuration to delete objects under a certain size to remove destroyed states #147

Open nitrocode opened 1 year ago

nitrocode commented 1 year ago

Describe the Feature

It's nice to look at the s3 state bucket to see which components and root dirs contain resources

After destroying root components and resources, the state file object continues to exist in s3. The state object has very few characters in there. It would be nice to expire these objects when they are less than a certain number of bytes.

Expected Behavior

Expire s3 state objects when the objects are less than N bytes

Use Case

See above

Describe Ideal Solution

Lifecycle rule

Alternatives Considered

N/A

Additional Context

Gowiem commented 5 months ago

It's kinda sketchy to do this, but I would like to see it if it's possible... We do enable versioning by default, right? So that should give us some confidence that this won't just outright destroy state that is actually being used. That said, I could see this being a problem... added some labels to see if anyone wants to implement and then we can discuss more once it's in a PR.