Skip to content

Commit

Permalink
make s3 lifecycle configuration conditional based on whether expirati…
Browse files Browse the repository at this point in the history
…on days are set
  • Loading branch information
markdboyd committed May 20, 2024
1 parent 77a1294 commit ead61af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ resource "aws_s3_bucket_acl" "encrypted_bucket_acl" {

resource "aws_s3_bucket_lifecycle_configuration" "encrypted_bucket_lifecycle" {
bucket = aws_s3_bucket.encrypted_bucket.id
# since the only rule is an expiration rule, we only create the lifecycle
# configuration if expiration days are set
count = var.expiration_days == 0 ? 0 : 1

dynamic "rule" {
# if expiration_days is 0 then the rule is not created
for_each = var.expiration_days == 0 ? [] : [var.expiration_days]

content {
id = "expiration-rule"
id = "expiration-rule"
# if expiration_days is 0 then the rule is disabled
status = "Enabled"

expiration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ resource "aws_s3_bucket_versioning" "encrypted_bucket_versioning" {

resource "aws_s3_bucket_lifecycle_configuration" "encrypted_bucket_lifecycle" {
bucket = aws_s3_bucket.encrypted_bucket.id

# since the only rule is an expiration rule, we only create the lifecycle
# configuration if expiration days are set
count = var.expiration_days == 0 ? 0 : 1

dynamic "rule" {
# if expiration_days is 0 then the rule is not created
for_each = var.expiration_days == 0 ? [] : [var.expiration_days]
Expand Down

0 comments on commit ead61af

Please sign in to comment.