Skip to content

Commit cb1cf1c

Browse files
authored
Merge pull request #2 from danbarr:add-lifecycle-config
Add lifecycle configuration
2 parents 13213e8 + 7a29986 commit cb1cf1c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ resource "aws_s3_bucket_versioning" "www_bucket" {
9393
}
9494
}
9595

96+
resource "aws_s3_bucket_lifecycle_configuration" "www_bucket" {
97+
depends_on = [aws_s3_bucket_versioning.www_bucket]
98+
bucket = aws_s3_bucket.www_bucket.id
99+
rule {
100+
id = "expire"
101+
status = "Enabled"
102+
filter {}
103+
104+
noncurrent_version_expiration {
105+
noncurrent_days = var.expired_version_retention_days
106+
}
107+
}
108+
}
109+
96110
resource "random_integer" "product" {
97111
min = 0
98112
max = length(local.hashi_products) - 1

variables.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@ variable "department" {
1818
description = "Value for the department tag."
1919
default = "WebDev"
2020
}
21+
22+
variable "expired_version_retention_days" {
23+
type = number
24+
description = "Number of days to retain expired versions."
25+
validation {
26+
condition = var.expired_version_retention_days > 0 && var.expired_version_retention_days <= 365
27+
error_message = "Please choose a value between 1 and 365 days."
28+
}
29+
}

0 commit comments

Comments
 (0)