Skip to content

Commit 0db3d55

Browse files
authored
feat: Added object lock configuration to the export bucket. (#8)
1 parent 1513f95 commit 0db3d55

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

tofu/modules/system/main.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,17 @@ module "s3" {
7777

7878
tags = var.tags
7979
}
80+
81+
resource "aws_s3_bucket_object_lock_configuration" "export" {
82+
for_each = var.export_lock_mode != "DISABLED" ? toset(["this"]) : toset([])
83+
84+
bucket = module.s3.bucket
85+
86+
rule {
87+
default_retention {
88+
mode = var.export_lock_mode
89+
days = var.export_lock_period == "days" ? var.export_lock_age : null
90+
years = var.export_lock_period == "years" ? var.export_lock_age : null
91+
}
92+
}
93+
}

tofu/modules/system/variables.tf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,34 @@ variable "export_expiration" {
1010
description = "Number of days before export files expire."
1111
}
1212

13+
variable "export_lock_age" {
14+
type = number
15+
description = "Age (based on the lock period) of an object before the lock is removed."
16+
default = 30
17+
}
18+
19+
variable "export_lock_mode" {
20+
type = string
21+
description = "Object lock mode for the export bucket."
22+
default = "GOVERNANCE"
23+
24+
validation {
25+
condition = contains(["COMPLIANCE", "GOVERNANCE", "DISABLED"], var.export_lock_mode)
26+
error_message = "Valid object lock modes are: COMPLIANCE, GOVERNANCE, or DISABLED."
27+
}
28+
}
29+
30+
variable "export_lock_period" {
31+
type = string
32+
description = "Period for which objects are locked. Valid values are days or years."
33+
default = "days"
34+
35+
validation {
36+
condition = contains(["days", "years"], var.export_lock_period)
37+
error_message = "Valid object lock periods are: days, years."
38+
}
39+
}
40+
1341
variable "key_recovery_period" {
1442
type = number
1543
default = 30

0 commit comments

Comments
 (0)