Skip to content

Commit

Permalink
Enhance lifecycle object with optionals, limit length of bucket name (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuru authored May 8, 2023
1 parent 701e32d commit 68c18f4
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 19 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ Available targets:
| Name | Source | Version |
|------|--------|---------|
| <a name="module_aws_s3_bucket"></a> [aws\_s3\_bucket](#module\_aws\_s3\_bucket) | cloudposse/s3-bucket/aws | 3.1.0 |
| <a name="module_bucket_name"></a> [bucket\_name](#module\_bucket\_name) | cloudposse/label/null | 0.25.0 |
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |

## Resources
Expand Down Expand Up @@ -246,7 +247,7 @@ Available targets:
| <a name="input_label_order"></a> [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.<br>Defaults to ["namespace", "environment", "stage", "name", "attributes"].<br>You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no |
| <a name="input_label_value_case"></a> [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,<br>set as tag values, and output by this module individually.<br>Does not affect values of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper` and `none` (no transformation).<br>Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.<br>Default value: `lower`. | `string` | `null` | no |
| <a name="input_labels_as_tags"></a> [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.<br>Default is to include all labels.<br>Tags with empty values will not be included in the `tags` output.<br>Set to `[]` to suppress all generated tags.<br>**Notes:**<br> The value of the `name` tag, if included, will be the `id`, not the `name`.<br> Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be<br> changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` | <pre>[<br> "default"<br>]</pre> | no |
| <a name="input_lifecycle_configuration_rules"></a> [lifecycle\_configuration\_rules](#input\_lifecycle\_configuration\_rules) | A list of S3 bucket v2 lifecycle rules, as specified in [terraform-aws-s3-bucket](https://github.com/cloudposse/terraform-aws-s3-bucket)"<br>These rules are not affected by the deprecated `lifecycle_rule_enabled` flag.<br>**NOTE:** Unless you also set `lifecycle_rule_enabled = false` you will also get the default deprecated rules set on your bucket. | <pre>list(object({<br> enabled = bool<br> id = string<br><br> abort_incomplete_multipart_upload_days = number<br><br> # `filter_and` is the `and` configuration block inside the `filter` configuration.<br> # This is the only place you should specify a prefix.<br> filter_and = any<br> expiration = any<br> transition = list(any)<br><br> noncurrent_version_expiration = any<br> noncurrent_version_transition = list(any)<br> }))</pre> | `[]` | no |
| <a name="input_lifecycle_configuration_rules"></a> [lifecycle\_configuration\_rules](#input\_lifecycle\_configuration\_rules) | A list of S3 bucket v2 lifecycle rules, as specified in [terraform-aws-s3-bucket](https://github.com/cloudposse/terraform-aws-s3-bucket)"<br>These rules are not affected by the deprecated `lifecycle_rule_enabled` flag.<br>**NOTE:** Unless you also set `lifecycle_rule_enabled = false` you will also get the default deprecated rules set on your bucket. | <pre>list(object({<br> enabled = bool<br> id = string<br><br> abort_incomplete_multipart_upload_days = number<br><br> # `filter_and` is the `and` configuration block inside the `filter` configuration.<br> # This is the only place you should specify a prefix.<br> filter_and = optional(object({<br> object_size_greater_than = optional(number) # integer >= 0<br> object_size_less_than = optional(number) # integer >= 1<br> prefix = optional(string)<br> tags = optional(map(string))<br> }))<br> expiration = optional(object({<br> date = optional(string) # string, RFC3339 time format, GMT<br> days = optional(number) # integer > 0<br> expired_object_delete_marker = optional(bool)<br> }))<br> noncurrent_version_expiration = optional(object({<br> newer_noncurrent_versions = optional(number) # integer > 0<br> noncurrent_days = optional(number) # integer >= 0<br> }))<br> transition = optional(list(object({<br> date = optional(string) # string, RFC3339 time format, GMT<br> days = optional(number) # integer >= 0<br> storage_class = string # string/enum, one of GLACIER, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING, DEEP_ARCHIVE, GLACIER_IR.<br> })), [])<br> noncurrent_version_transition = optional(list(object({<br> newer_noncurrent_versions = optional(number) # integer >= 0<br> noncurrent_days = optional(number) # integer >= 0<br> storage_class = string # string/enum, one of GLACIER, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING, DEEP_ARCHIVE, GLACIER_IR.<br> })), [])<br> }))</pre> | `[]` | no |
| <a name="input_lifecycle_prefix"></a> [lifecycle\_prefix](#input\_lifecycle\_prefix) | (Deprecated, use `lifecycle_configuration_rules` instead)<br>Prefix filter. Used to manage object lifecycle events | `string` | `null` | no |
| <a name="input_lifecycle_rule_enabled"></a> [lifecycle\_rule\_enabled](#input\_lifecycle\_rule\_enabled) | DEPRECATED: Use `lifecycle_configuration_rules` instead.<br>When `true`, configures lifecycle events on this bucket using individual (now deprecated) variables.<br>When `false`, lifecycle events are not configured using individual (now deprecated) variables, but `lifecycle_configuration_rules` still apply.<br>When `null`, lifecycle events are configured using individual (now deprecated) variables only if `lifecycle_configuration_rules` is empty. | `bool` | `null` | no |
| <a name="input_lifecycle_tags"></a> [lifecycle\_tags](#input\_lifecycle\_tags) | (Deprecated, use `lifecycle_configuration_rules` instead)<br>Tags filter. Used to manage object lifecycle events | `map(string)` | `null` | no |
Expand Down
3 changes: 2 additions & 1 deletion docs/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
| Name | Source | Version |
|------|--------|---------|
| <a name="module_aws_s3_bucket"></a> [aws\_s3\_bucket](#module\_aws\_s3\_bucket) | cloudposse/s3-bucket/aws | 3.1.0 |
| <a name="module_bucket_name"></a> [bucket\_name](#module\_bucket\_name) | cloudposse/label/null | 0.25.0 |
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |

## Resources
Expand Down Expand Up @@ -66,7 +67,7 @@
| <a name="input_label_order"></a> [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.<br>Defaults to ["namespace", "environment", "stage", "name", "attributes"].<br>You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no |
| <a name="input_label_value_case"></a> [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,<br>set as tag values, and output by this module individually.<br>Does not affect values of tags passed in via the `tags` input.<br>Possible values: `lower`, `title`, `upper` and `none` (no transformation).<br>Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.<br>Default value: `lower`. | `string` | `null` | no |
| <a name="input_labels_as_tags"></a> [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.<br>Default is to include all labels.<br>Tags with empty values will not be included in the `tags` output.<br>Set to `[]` to suppress all generated tags.<br>**Notes:**<br> The value of the `name` tag, if included, will be the `id`, not the `name`.<br> Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be<br> changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` | <pre>[<br> "default"<br>]</pre> | no |
| <a name="input_lifecycle_configuration_rules"></a> [lifecycle\_configuration\_rules](#input\_lifecycle\_configuration\_rules) | A list of S3 bucket v2 lifecycle rules, as specified in [terraform-aws-s3-bucket](https://github.com/cloudposse/terraform-aws-s3-bucket)"<br>These rules are not affected by the deprecated `lifecycle_rule_enabled` flag.<br>**NOTE:** Unless you also set `lifecycle_rule_enabled = false` you will also get the default deprecated rules set on your bucket. | <pre>list(object({<br> enabled = bool<br> id = string<br><br> abort_incomplete_multipart_upload_days = number<br><br> # `filter_and` is the `and` configuration block inside the `filter` configuration.<br> # This is the only place you should specify a prefix.<br> filter_and = any<br> expiration = any<br> transition = list(any)<br><br> noncurrent_version_expiration = any<br> noncurrent_version_transition = list(any)<br> }))</pre> | `[]` | no |
| <a name="input_lifecycle_configuration_rules"></a> [lifecycle\_configuration\_rules](#input\_lifecycle\_configuration\_rules) | A list of S3 bucket v2 lifecycle rules, as specified in [terraform-aws-s3-bucket](https://github.com/cloudposse/terraform-aws-s3-bucket)"<br>These rules are not affected by the deprecated `lifecycle_rule_enabled` flag.<br>**NOTE:** Unless you also set `lifecycle_rule_enabled = false` you will also get the default deprecated rules set on your bucket. | <pre>list(object({<br> enabled = bool<br> id = string<br><br> abort_incomplete_multipart_upload_days = number<br><br> # `filter_and` is the `and` configuration block inside the `filter` configuration.<br> # This is the only place you should specify a prefix.<br> filter_and = optional(object({<br> object_size_greater_than = optional(number) # integer >= 0<br> object_size_less_than = optional(number) # integer >= 1<br> prefix = optional(string)<br> tags = optional(map(string))<br> }))<br> expiration = optional(object({<br> date = optional(string) # string, RFC3339 time format, GMT<br> days = optional(number) # integer > 0<br> expired_object_delete_marker = optional(bool)<br> }))<br> noncurrent_version_expiration = optional(object({<br> newer_noncurrent_versions = optional(number) # integer > 0<br> noncurrent_days = optional(number) # integer >= 0<br> }))<br> transition = optional(list(object({<br> date = optional(string) # string, RFC3339 time format, GMT<br> days = optional(number) # integer >= 0<br> storage_class = string # string/enum, one of GLACIER, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING, DEEP_ARCHIVE, GLACIER_IR.<br> })), [])<br> noncurrent_version_transition = optional(list(object({<br> newer_noncurrent_versions = optional(number) # integer >= 0<br> noncurrent_days = optional(number) # integer >= 0<br> storage_class = string # string/enum, one of GLACIER, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING, DEEP_ARCHIVE, GLACIER_IR.<br> })), [])<br> }))</pre> | `[]` | no |
| <a name="input_lifecycle_prefix"></a> [lifecycle\_prefix](#input\_lifecycle\_prefix) | (Deprecated, use `lifecycle_configuration_rules` instead)<br>Prefix filter. Used to manage object lifecycle events | `string` | `null` | no |
| <a name="input_lifecycle_rule_enabled"></a> [lifecycle\_rule\_enabled](#input\_lifecycle\_rule\_enabled) | DEPRECATED: Use `lifecycle_configuration_rules` instead.<br>When `true`, configures lifecycle events on this bucket using individual (now deprecated) variables.<br>When `false`, lifecycle events are not configured using individual (now deprecated) variables, but `lifecycle_configuration_rules` still apply.<br>When `null`, lifecycle events are configured using individual (now deprecated) variables only if `lifecycle_configuration_rules` is empty. | `bool` | `null` | no |
| <a name="input_lifecycle_tags"></a> [lifecycle\_tags](#input\_lifecycle\_tags) | (Deprecated, use `lifecycle_configuration_rules` instead)<br>Tags filter. Used to manage object lifecycle events | `map(string)` | `null` | no |
Expand Down
17 changes: 14 additions & 3 deletions examples/complete/fixtures.us-east-2.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ lifecycle_configuration_rules = [

abort_incomplete_multipart_upload_days = 1 # number

filter_and = null
expiration = null
transition = null
# filter_and = null
# expiration = null
# transition = null
filter_and = {
prefix = "prefix/"
}
noncurrent_version_expiration = {
newer_noncurrent_versions = 3 # integer > 0
noncurrent_days = 90 # integer >= 0
Expand All @@ -27,5 +30,13 @@ lifecycle_configuration_rules = [
noncurrent_days = 30 # integer >= 0
storage_class = "ONEZONE_IA" # string/enum, one of GLACIER, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING, DEEP_ARCHIVE, GLACIER_IR.
}]
},
{
enabled = true
id = "cleanup-delete-markers"
expiration = {
expired_object_delete_marker = true
}
abort_incomplete_multipart_upload_days = 1
}
]
35 changes: 28 additions & 7 deletions examples/complete/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,38 @@ variable "lifecycle_configuration_rules" {

# `filter_and` is the `and` configuration block inside the `filter` configuration.
# This is the only place you should specify a prefix.
filter_and = any
expiration = any
transition = list(any)

noncurrent_version_expiration = any
noncurrent_version_transition = list(any)
filter_and = optional(object({
object_size_greater_than = optional(number) # integer >= 0
object_size_less_than = optional(number) # integer >= 1
prefix = optional(string)
tags = optional(map(string))
}))
expiration = optional(object({
date = optional(string) # string, RFC3339 time format, GMT
days = optional(number) # integer > 0
expired_object_delete_marker = optional(bool)
}))
noncurrent_version_expiration = optional(object({
newer_noncurrent_versions = optional(number) # integer > 0
noncurrent_days = optional(number) # integer >= 0
}))
transition = optional(list(object({
date = optional(string) # string, RFC3339 time format, GMT
days = optional(number) # integer >= 0
storage_class = string # string/enum, one of GLACIER, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING, DEEP_ARCHIVE, GLACIER_IR.
})), [])
noncurrent_version_transition = optional(list(object({
newer_noncurrent_versions = optional(number) # integer >= 0
noncurrent_days = optional(number) # integer >= 0
storage_class = string # string/enum, one of GLACIER, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING, DEEP_ARCHIVE, GLACIER_IR.
})), [])
}))
default = []

description = <<-EOT
A list of S3 bucket v2 lifecycle rules, as specified in [terraform-aws-s3-bucket](https://github.com/cloudposse/terraform-aws-s3-bucket)"
These rules are not affected by the deprecated `lifecycle_rule_enabled` flag.
**NOTE:** Unless you also set `lifecycle_rule_enabled = false` you will also get the default deprecated rules set on your bucket.
EOT
default = []
nullable = false
}
14 changes: 13 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
locals {
# We do not use coalesce() here because it is OK if local.bucket_name is empty.
bucket_name = var.bucket_name == null || var.bucket_name == "" ? module.this.id : var.bucket_name
bucket_name = var.bucket_name == null || var.bucket_name == "" ? module.bucket_name.id : var.bucket_name
}

module "bucket_name" {
source = "cloudposse/label/null"
version = "0.25.0"

enabled = local.enabled && try(length(var.bucket_name) == 0, false)

id_length_limit = 63 # https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html

context = module.this.context
}


module "aws_s3_bucket" {
source = "cloudposse/s3-bucket/aws"
version = "3.1.0"
Expand Down
32 changes: 26 additions & 6 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,33 @@ variable "lifecycle_configuration_rules" {

# `filter_and` is the `and` configuration block inside the `filter` configuration.
# This is the only place you should specify a prefix.
filter_and = any
expiration = any
transition = list(any)

noncurrent_version_expiration = any
noncurrent_version_transition = list(any)
filter_and = optional(object({
object_size_greater_than = optional(number) # integer >= 0
object_size_less_than = optional(number) # integer >= 1
prefix = optional(string)
tags = optional(map(string))
}))
expiration = optional(object({
date = optional(string) # string, RFC3339 time format, GMT
days = optional(number) # integer > 0
expired_object_delete_marker = optional(bool)
}))
noncurrent_version_expiration = optional(object({
newer_noncurrent_versions = optional(number) # integer > 0
noncurrent_days = optional(number) # integer >= 0
}))
transition = optional(list(object({
date = optional(string) # string, RFC3339 time format, GMT
days = optional(number) # integer >= 0
storage_class = string # string/enum, one of GLACIER, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING, DEEP_ARCHIVE, GLACIER_IR.
})), [])
noncurrent_version_transition = optional(list(object({
newer_noncurrent_versions = optional(number) # integer >= 0
noncurrent_days = optional(number) # integer >= 0
storage_class = string # string/enum, one of GLACIER, STANDARD_IA, ONEZONE_IA, INTELLIGENT_TIERING, DEEP_ARCHIVE, GLACIER_IR.
})), [])
}))

description = <<-EOT
A list of S3 bucket v2 lifecycle rules, as specified in [terraform-aws-s3-bucket](https://github.com/cloudposse/terraform-aws-s3-bucket)"
These rules are not affected by the deprecated `lifecycle_rule_enabled` flag.
Expand Down

0 comments on commit 68c18f4

Please sign in to comment.