Skip to content

Commit db1cf54

Browse files
committed
chore: s3 delete old files
1 parent cacb3de commit db1cf54

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

infra/modules/aws/code_bucket/main.tf

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,18 @@ resource "aws_s3_bucket_ownership_controls" "lambda" {
1010
object_ownership = "BucketOwnerEnforced"
1111
}
1212
}
13+
14+
resource "aws_s3_bucket_lifecycle_configuration" "delete_old_files" {
15+
count = var.s3_expiration_days > 0 ? 1 : 0
16+
17+
bucket = aws_s3_bucket.lambda.id
18+
19+
rule {
20+
id = "delete-expired-objects"
21+
status = "Enabled"
22+
23+
expiration {
24+
days = var.s3_expiration_days
25+
}
26+
}
27+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1+
### start of static vars set in root.hcl ###
12
variable "lambda_bucket" {
23
description = "S3 bucket to host lambda code files"
34
type = string
45
}
6+
### end of static vars set in root.hcl ###
7+
8+
9+
variable "s3_expiration_days" {
10+
description = "Number of days before objects are deleted (set to 0 to disable)"
11+
type = number
12+
default = 0
13+
}

0 commit comments

Comments
 (0)