Skip to content

Commit

Permalink
Merge pull request #78 from Flaconi/OPS-5217-extend-lifecycle-settings
Browse files Browse the repository at this point in the history
Ops 5217 extend lifecycle settings
  • Loading branch information
ronny-panknin-flaconi authored Mar 2, 2023
2 parents ceb2062 + a45172b commit 544652e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
11 changes: 1 addition & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1742,16 +1742,7 @@ Default: `"Enabled"`

Description: S3 Lifecycle rules

Type:

```hcl
list(object({
id = string
status = string
prefix = string
expiration_days = number
}))
```
Type: `any`

Default: `[]`

Expand Down
19 changes: 17 additions & 2 deletions examples/s3/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,28 @@ module "ms_sample_s3" {
id = "all-cleanup"
status = "Enabled"
prefix = ""
expiration_days = 90
expiration = {
days = 90
}
},
{
id = "tmp"
status = "Enabled"
prefix = "tmp/"
expiration_days = 1
expiration = {
days = 1
}
},
{
id = "MoveAllToGlacierAfterTwoWeeks"
status = "Enabled"
prefix = ""
transition = [
{
days = 28
storage_class = "GLACIER"
}
]
}
]

Expand Down
19 changes: 17 additions & 2 deletions s3.tf
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,23 @@ resource "aws_s3_bucket_lifecycle_configuration" "this" {
filter {
prefix = rule.value.prefix
}
expiration {
days = rule.value.expiration_days

dynamic "expiration" {
for_each = length(keys(lookup(rule.value, "expiration", {}))) == 0 ? [] : [lookup(rule.value, "expiration", {})]

content {
date = lookup(expiration.value, "date", null)
days = lookup(expiration.value, "days", null)
expired_object_delete_marker = lookup(expiration.value, "expired_object_delete_marker", null)
}
}
dynamic "transition" {
for_each = lookup(rule.value, "transition", [])
content {
date = lookup(transition.value, "date", null)
days = lookup(transition.value, "days", null)
storage_class = transition.value.storage_class
}
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -1137,12 +1137,7 @@ variable "s3_versioning_enabled" {
variable "s3_lifecycle_rules" {
description = "S3 Lifecycle rules"
default = []
type = list(object({
id = string
status = string
prefix = string
expiration_days = number
}))
type = any
}

# -------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 544652e

Please sign in to comment.