File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -136,7 +136,7 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "bucket" {
136136# Lifecycle configuration for the dev buckets to remove all objects older than var.lifecycle_expiration_days.
137137resource "aws_s3_bucket_lifecycle_configuration" "lifecycle_expiration_days" {
138138 # # Iterate over the list from var's to avoid some chicken/egg problems
139- for_each = var. lifecycle_expiration_days > 0 ? toset (var. s3_bucket_names ) : []
139+ for_each = var. lifecycle_expiration_days || var . version_lifecycle_expiration_days > 0 ? toset (var. s3_bucket_names ) : []
140140 # # Refer to the id from the bucket resource to retain the dependency
141141 bucket = aws_s3_bucket. landing_zone_buckets [each . value ]. id
142142
@@ -154,4 +154,19 @@ resource "aws_s3_bucket_lifecycle_configuration" "lifecycle_expiration_days" {
154154 }
155155 }
156156 }
157+
158+ dynamic "version_rule" {
159+ for_each = var. version_lifecycle_expiration_days > 0 ? [1 ] : []
160+
161+ content {
162+ id = " delete-old-versions"
163+ status = " Enabled"
164+ expiration {
165+ days = var. version_lifecycle_expiration_days
166+ }
167+ noncurrent_version_expiration {
168+ noncurrent_days = 7
169+ }
170+ }
171+ }
157172}
Original file line number Diff line number Diff line change @@ -31,6 +31,12 @@ variable "lifecycle_expiration_days" {
3131 description = " Number of days for object lifecycle to expire the objects in dev env. Defaults to 0, which disables the rule"
3232}
3333
34+ variable "version_lifecycle_expiration_days" {
35+ type = number
36+ default = " 0"
37+ description = " Number of days for a bucket version's lifecycle to expire. Defaults to 0, which disables the rule"
38+ }
39+
3440variable "versioning_enabled" {
3541 type = bool
3642 default = false
You can’t perform that action at this time.
0 commit comments