Skip to content

Commit

Permalink
Allow to enable S3 lifecycle for snapshot bucket.
Browse files Browse the repository at this point in the history
  • Loading branch information
owl-king committed Aug 2, 2024
1 parent 73900a0 commit 446fb63
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
17 changes: 16 additions & 1 deletion indexer/s3_bucket.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,34 @@ resource "aws_s3_bucket" "indexer_full_node_snapshots" {
}
}

# Enable S3 snapshot lifecycle to clean up old snapshots
resource "aws_s3_bucket_lifecycle_configuration" "indexer_full_node_snapshots" {
count = var.enable_s3_snapshot_lifecycle ? 1 : 0
bucket = aws_s3_bucket.indexer_full_node_snapshots.id

rule {
id = "expire-old-snapshots"
status = "Enabled"

expiration {
days = var.snapshot_bucket_expiration_days
}
}
}

# Enable S3 bucket metrics to be sent to Datadog for monitoring
resource "aws_s3_bucket_metric" "indexer_full_node_snapshots" {
bucket = aws_s3_bucket.indexer_full_node_snapshots.id
name = "EntireBucket"
}


# Attach policy to s3 bucket to allow load balancer to write logs to the S3 bucket
# NOTE: This resource cannot be tagged.
resource "aws_s3_bucket_policy" "lb_s3_bucket_policy" {
bucket = aws_s3_bucket.load_balancer.id
policy = data.aws_iam_policy_document.lb_s3_bucket_policy.json
}

# Policy to allow load balancer to write logs into the s3 bucket
data "aws_iam_policy_document" "lb_s3_bucket_policy" {
statement {
Expand Down
12 changes: 12 additions & 0 deletions indexer/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -472,3 +472,15 @@ variable "image_count" {
description = "Number of images to store for ECR, defaults to 100."
default = 100
}

variable "enable_s3_snapshot_lifecycle" {
type = bool
description = "Enables S3 lifecycle on snapshot bucket. Default is true"
default = true
}

variable "snapshot_bucket_expiration_days" {
type = number
description = "Number of days to store fullnode snapshot on S3, defaults to 7."
default = 7
}

0 comments on commit 446fb63

Please sign in to comment.