Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1bf32b3

Browse files
Merge pull request segmentio#73 from Edencia/s3-logs-expiration
S3 logs expiration
2 parents 03c9279 + a7fd045 commit 1bf32b3

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

main.tf

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ variable "extra_cloud_config_content" {
139139
default = ""
140140
}
141141

142+
variable "logs_expiration_enabled" {
143+
default = false
144+
}
145+
146+
variable "logs_expiration_days" {
147+
default = 30
148+
}
149+
142150
module "defaults" {
143151
source = "./defaults"
144152
region = "${var.region}"
@@ -219,10 +227,12 @@ module "ecs_cluster" {
219227
}
220228

221229
module "s3_logs" {
222-
source = "./s3-logs"
223-
name = "${var.name}"
224-
environment = "${var.environment}"
225-
account_id = "${module.defaults.s3_logs_account_id}"
230+
source = "./s3-logs"
231+
name = "${var.name}"
232+
environment = "${var.environment}"
233+
account_id = "${module.defaults.s3_logs_account_id}"
234+
logs_expiration_enabled = "${var.logs_expiration_enabled}"
235+
logs_expiration_days = "${var.logs_expiration_days}"
226236
}
227237

228238
// The region in which the infra lives.

s3-logs/main.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ variable "environment" {
77
variable "account_id" {
88
}
99

10+
variable "logs_expiration_enabled" {
11+
default = false
12+
}
13+
14+
variable "logs_expiration_days" {
15+
default = 30
16+
}
17+
1018
data "template_file" "policy" {
1119
template = "${file("${path.module}/policy.json")}"
1220

@@ -19,6 +27,16 @@ data "template_file" "policy" {
1927
resource "aws_s3_bucket" "logs" {
2028
bucket = "${var.name}-${var.environment}-logs"
2129

30+
lifecycle_rule {
31+
id = "logs-expiration"
32+
prefix = ""
33+
enabled = "${var.logs_expiration_enabled}"
34+
35+
expiration {
36+
days = "${var.logs_expiration_days}"
37+
}
38+
}
39+
2240
tags {
2341
Name = "${var.name}-${var.environment}-logs"
2442
Environment = "${var.environment}"

0 commit comments

Comments
 (0)