Created
November 10, 2022 21:25
-
-
Save grimm26/348423ffb5c244c70fd6e0cc15238a54 to your computer and use it in GitHub Desktop.
handle presets and custom
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "object_lifecycle_preset" { | |
description = <<-EOL | |
Choose a pre-configured set of object lifecycle rules for your bucket. | |
- empty_bucket: Delete all objects from the bucket. Use this in preparation to destroy the bucket. This is non-recoverable. | |
EOL | |
type = string | |
default = "default" | |
validation { | |
condition = contains(["empty_bucket", "default"], var.object_lifecycle_preset) | |
error_message = "You must select from one of the available presets: empty_bucket." | |
} | |
} | |
variable "lifecycle_object_rules" { | |
description = "List of object describing object lifecycle rules on the noncurrent versions of objects." | |
type = list(object( | |
{ | |
id = string | |
enabled = bool | |
prefix = optional(string) | |
tags = optional(map(string), {}) | |
object_size_greater_than = optional(number) | |
object_size_less_than = optional(number) | |
abort_incomplete_multipart_upload_days = optional(number) | |
transitions = optional(map(string), {}) | |
noncurrent_transitions = optional(map(string), {}) | |
} | |
)) | |
default = [] | |
} | |
locals { | |
lifecycle_presets = { | |
default = [ | |
{ | |
id = "default noncurrent transition" | |
# prefix = "foo/bar/" | |
# tags = { "key" = "value", "key2" = "value2" } | |
enabled = true | |
# transitions = { | |
# standard_ia = 120 | |
# } | |
object_size_greater_than = 1024 * 128 | |
noncurrent_transitions = { | |
standard_ia = 30 | |
} | |
}, | |
{ | |
id = "default noncurrent expiration" | |
enabled = true | |
abort_incomplete_multipart_upload_days = 1 | |
noncurrent_transitions = { | |
expiration = 120 | |
} | |
transitions = { | |
expired_object_delete_marker = true | |
} | |
}, | |
] | |
empty_bucket = [ | |
{ | |
id = "empty bucket1" | |
enabled = true | |
noncurrent_transitions = { | |
expiration = 1 | |
} | |
transitions = { | |
expiration = 1 | |
} | |
abort_incomplete_multipart_upload_days = 1 | |
}, | |
{ | |
id = "empty bucket2" | |
enabled = true | |
transitions = { | |
expired_object_delete_marker = true | |
} | |
}, | |
] | |
} | |
# If we have custom rules specified, use those. Otherwise use the preset. | |
lifecycle_object_rules = length(var.lifecycle_object_rules) > 0 ? var.lifecycle_object_rules : local.lifecycle_presets[var.object_lifecycle_preset] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment