Skip to content

Commit d6ce4bb

Browse files
committed
setup smart deletion rules
1 parent a7cae88 commit d6ce4bb

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

terraform/envs/prod/main.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ module "archival" {
8282
RunEnvironment = "dev"
8383
LogRetentionDays = var.LogRetentionDays
8484
BucketPrefix = local.bucket_prefix
85-
MonitorTables = ["${var.ProjectId}-audit-log", "${var.ProjectId}-events", "${var.ProjectId}-room-requests", "${var.ProjectId}-room-requests-status"]
85+
MonitorTables = ["${var.ProjectId}-audit-log", "${var.ProjectId}-events", "${var.ProjectId}-room-requests"]
86+
TableDeletionDays = tomap({
87+
"${var.ProjectId}-audit-log" : 730,
88+
"${var.ProjectId}-room-requests" : 730
89+
# events are held forever as a cool historical archive - if no one reads them it shouldn't cost us much.
90+
})
8691
}
8792

8893
module "lambdas" {

terraform/modules/archival/main.tf

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,41 @@ resource "aws_s3_bucket_lifecycle_configuration" "this" {
4949
id = "intelligent-tiering-transition"
5050
status = "Enabled"
5151

52+
filter {}
53+
5254
transition {
5355
days = 1
5456
storage_class = "INTELLIGENT_TIERING"
5557
}
5658
}
59+
60+
rule {
61+
id = "ExpireNoncurrentVersions"
62+
status = "Enabled"
63+
64+
filter {}
65+
66+
noncurrent_version_expiration {
67+
noncurrent_days = 5
68+
}
69+
}
70+
71+
dynamic "rule" {
72+
for_each = var.TableDeletionDays
73+
74+
content {
75+
id = "expire-${rule.key}"
76+
status = "Enabled"
77+
78+
filter {
79+
prefix = "resource=${rule.key}/"
80+
}
81+
82+
expiration {
83+
days = rule.value
84+
}
85+
}
86+
}
5787
}
5888

5989
resource "aws_s3_bucket_intelligent_tiering_configuration" "this" {

terraform/modules/archival/variables.tf

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ variable "BucketPrefix" {
77
type = string
88
}
99

10-
variable "MonitorTables" {
11-
type = set(string)
12-
description = "DynamoDB to monitor expire events for and archive."
13-
}
1410

1511
variable "LogRetentionDays" {
1612
type = number
@@ -23,3 +19,13 @@ variable "RunEnvironment" {
2319
error_message = "The lambda run environment must be dev or prod."
2420
}
2521
}
22+
23+
variable "MonitorTables" {
24+
type = set(string)
25+
description = "DynamoDB to monitor expire events for and archive."
26+
}
27+
28+
variable "TableDeletionDays" {
29+
type = map(string, number)
30+
description = "Number of days for a given day to hold onto the records once it is put into the bucket."
31+
}

0 commit comments

Comments
 (0)