Skip to content
This repository has been archived by the owner on Sep 27, 2024. It is now read-only.

Commit

Permalink
BATIAI-1398 updated code to have 7 day expiration on dev environments (
Browse files Browse the repository at this point in the history
…#6)

* BATIAI-1398 updated code to have 7 day expiration on dev environments
  • Loading branch information
arunsanna authored Mar 29, 2023
1 parent d13cb27 commit 42b2be8
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Ignore files generated by Terraform
.terraform
*.terraform.lock.hcl

# Ignore .tfstate files
*.tfstate
*.tfstate.*

# Ignore crash log files
crash.log

# Ignore override files
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Ignore provider plugin files
.terraformrc
terraform.rc

# Ignore sensitive files
*.pem
*.key
*.pub
*.cer
*.crt
*.jks
*.p12
*.pfx

# Ignore local development files
.envrc
.env
22 changes: 22 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,25 @@ resource "aws_s3_bucket_server_side_encryption_configuration" "bucket" {
}
}
}

# Lifecycle configuration for the dev buckets to remove all objects older than var.lifecycle_expiration_days.
resource "aws_s3_bucket_lifecycle_configuration" "lifecycle_expiration_days" {
for_each = var.lifecycle_expiration_days > 0 ? aws_s3_bucket.landing_zone_buckets : []

bucket = each.value.id

dynamic "rule" {
for_each = var.lifecycle_expiration_days > 0 ? [1] : []

content {
id = "delete-old-objects"
status = "Enabled"
expiration {
days = var.lifecycle_expiration_days
}
noncurrent_version_expiration {
noncurrent_days = 1
}
}
}
}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@ variable "sse_algorithm" {
default = "aws:kms"
description = "The server-side encryption algorithm to use. Valid values are AES256 and aws:kms, defaults to aws:kms."
}

variable "lifecycle_expiration_days" {
type = string
default = "0"
description = "Number of days for object lifecycle to expire the objects in dev env. Defaults to 0, which disables the rule"
}

0 comments on commit 42b2be8

Please sign in to comment.