Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to enable S3 lifecycle for snapshot bucket. #108

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are there other buckets (i.e. load_balancer logs) that the lifecycle should apply to?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I will add lifecycle to other buckets


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" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
variable "snapshot_bucket_expiration_days" {
variable "s3_snapshot_expiration_days" {

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