Skip to content

Commit

Permalink
fix: abort incomplete uploads to s3 bucket (#379)
Browse files Browse the repository at this point in the history
As a best practice to save costs there should be a lifecycle configuration on s3 buckets to abort incomplete uploads

https://docs.aws.amazon.com/AmazonS3/latest/userguide/mpu-abort-incomplete-mpu-lifecycle-config.html
  • Loading branch information
msvticket authored Sep 9, 2024
1 parent a8f9b98 commit 09ca279
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
12 changes: 12 additions & 0 deletions modules/backup/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "backup_bucket" {
}
}

resource "aws_s3_bucket_lifecycle_configuration" "backup_bucket" {
count = var.enable_backup ? 1 : 0
bucket = aws_s3_bucket.backup_bucket.id
rule {
status = "Enabled"
id = "abort_incomplete_uploads"
abort_incomplete_multipart_upload {
days_after_initiation = 7
}
}
}

// ----------------------------------------------------------------------------
// Setup IAM User and Policies for Velero
//
Expand Down
36 changes: 36 additions & 0 deletions modules/cluster/storage.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "logs_jenkins_x" {
}
}

resource "aws_s3_bucket_lifecycle_configuration" "logs_jenkins_x" {
count = var.enable_logs_storage ? 1 : 0
bucket = aws_s3_bucket.logs_jenkins_x.id
rule {
status = "Enabled"
id = "abort_incomplete_uploads"
abort_incomplete_multipart_upload {
days_after_initiation = 7
}
}
}

// ---------------------------------
// Configuration for reports bucket
// ---------------------------------
Expand Down Expand Up @@ -81,6 +93,18 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "reports_jenkins_x
}
}

resource "aws_s3_bucket_lifecycle_configuration" "reports_jenkins_x" {
count = var.enable_reports_storage ? 1 : 0
bucket = aws_s3_bucket.reports_jenkins_x.id
rule {
status = "Enabled"
id = "abort_incomplete_uploads"
abort_incomplete_multipart_upload {
days_after_initiation = 7
}
}
}

// ------------------------------------
// Configuration for repository bucket
// ------------------------------------
Expand Down Expand Up @@ -118,3 +142,15 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "repository_jenkin
}
}
}

resource "aws_s3_bucket_lifecycle_configuration" "repository_jenkins_x" {
count = var.enable_repository_storage ? 1 : 0
bucket = aws_s3_bucket.repository_jenkins_x.id
rule {
status = "Enabled"
id = "abort_incomplete_uploads"
abort_incomplete_multipart_upload {
days_after_initiation = 7
}
}
}

0 comments on commit 09ca279

Please sign in to comment.