From 7d787f3fca7c8c67a984a590b43940589335b41d Mon Sep 17 00:00:00 2001 From: Wojciech Szychta <62331374+wszychta@users.noreply.github.com> Date: Wed, 25 Aug 2021 17:41:54 +0200 Subject: [PATCH] Add additional variable enable_noncurrent_version_expiration (#90) * Add additional variable enable_noncurrent_version_expiration to give ability to not force noncurrent files translation * Autoformat changes * Push autoformat changes * Add new variables to test * Fix missing property in lifecycle_rules variable --- README.md | 2 +- docs/terraform.md | 2 +- examples/complete/lifecycle.us-east-2.tfvars | 18 ++++++++++-------- examples/complete/variables.tf | 18 ++++++++++-------- main.tf | 8 ++++++-- variables.tf | 18 ++++++++++-------- 6 files changed, 38 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 9b3060a7..26e7d7d6 100644 --- a/README.md +++ b/README.md @@ -273,7 +273,7 @@ Available targets: | [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no | | [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,
set as tag values, and output by this module individually.
Does not affect values of tags passed in via the `tags` input.
Possible values: `lower`, `title`, `upper` and `none` (no transformation).
Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.
Default value: `lower`. | `string` | `null` | no | | [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.
Default is to include all labels.
Tags with empty values will not be included in the `tags` output.
Set to `[]` to suppress all generated tags.
**Notes:**
The value of the `name` tag, if included, will be the `id`, not the `name`.
Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be
changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` |
[
"default"
]
| no | -| [lifecycle\_rules](#input\_lifecycle\_rules) | A list of lifecycle rules |
list(object({
prefix = string
enabled = bool
tags = map(string)

enable_glacier_transition = bool
enable_deeparchive_transition = bool
enable_standard_ia_transition = bool
enable_current_object_expiration = bool

abort_incomplete_multipart_upload_days = number
noncurrent_version_glacier_transition_days = number
noncurrent_version_deeparchive_transition_days = number
noncurrent_version_expiration_days = number

standard_transition_days = number
glacier_transition_days = number
deeparchive_transition_days = number
expiration_days = number
}))
|
[
{
"abort_incomplete_multipart_upload_days": 90,
"deeparchive_transition_days": 90,
"enable_current_object_expiration": true,
"enable_deeparchive_transition": false,
"enable_glacier_transition": true,
"enable_standard_ia_transition": false,
"enabled": false,
"expiration_days": 90,
"glacier_transition_days": 60,
"noncurrent_version_deeparchive_transition_days": 60,
"noncurrent_version_expiration_days": 90,
"noncurrent_version_glacier_transition_days": 30,
"prefix": "",
"standard_transition_days": 30,
"tags": {}
}
]
| no | +| [lifecycle\_rules](#input\_lifecycle\_rules) | A list of lifecycle rules |
list(object({
prefix = string
enabled = bool
tags = map(string)

enable_glacier_transition = bool
enable_deeparchive_transition = bool
enable_standard_ia_transition = bool
enable_current_object_expiration = bool
enable_noncurrent_version_expiration = bool

abort_incomplete_multipart_upload_days = number
noncurrent_version_glacier_transition_days = number
noncurrent_version_deeparchive_transition_days = number
noncurrent_version_expiration_days = number

standard_transition_days = number
glacier_transition_days = number
deeparchive_transition_days = number
expiration_days = number
}))
|
[
{
"abort_incomplete_multipart_upload_days": 90,
"deeparchive_transition_days": 90,
"enable_current_object_expiration": true,
"enable_deeparchive_transition": false,
"enable_glacier_transition": true,
"enable_noncurrent_version_expiration": true,
"enable_standard_ia_transition": false,
"enabled": false,
"expiration_days": 90,
"glacier_transition_days": 60,
"noncurrent_version_deeparchive_transition_days": 60,
"noncurrent_version_expiration_days": 90,
"noncurrent_version_glacier_transition_days": 30,
"prefix": "",
"standard_transition_days": 30,
"tags": {}
}
]
| no | | [logging](#input\_logging) | Bucket access logging configuration. |
object({
bucket_name = string
prefix = string
})
| `null` | no | | [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a `tag`.
The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no | | [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no | diff --git a/docs/terraform.md b/docs/terraform.md index 0df83583..c7df24b6 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -64,7 +64,7 @@ | [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no | | [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,
set as tag values, and output by this module individually.
Does not affect values of tags passed in via the `tags` input.
Possible values: `lower`, `title`, `upper` and `none` (no transformation).
Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.
Default value: `lower`. | `string` | `null` | no | | [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.
Default is to include all labels.
Tags with empty values will not be included in the `tags` output.
Set to `[]` to suppress all generated tags.
**Notes:**
The value of the `name` tag, if included, will be the `id`, not the `name`.
Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be
changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` |
[
"default"
]
| no | -| [lifecycle\_rules](#input\_lifecycle\_rules) | A list of lifecycle rules |
list(object({
prefix = string
enabled = bool
tags = map(string)

enable_glacier_transition = bool
enable_deeparchive_transition = bool
enable_standard_ia_transition = bool
enable_current_object_expiration = bool

abort_incomplete_multipart_upload_days = number
noncurrent_version_glacier_transition_days = number
noncurrent_version_deeparchive_transition_days = number
noncurrent_version_expiration_days = number

standard_transition_days = number
glacier_transition_days = number
deeparchive_transition_days = number
expiration_days = number
}))
|
[
{
"abort_incomplete_multipart_upload_days": 90,
"deeparchive_transition_days": 90,
"enable_current_object_expiration": true,
"enable_deeparchive_transition": false,
"enable_glacier_transition": true,
"enable_standard_ia_transition": false,
"enabled": false,
"expiration_days": 90,
"glacier_transition_days": 60,
"noncurrent_version_deeparchive_transition_days": 60,
"noncurrent_version_expiration_days": 90,
"noncurrent_version_glacier_transition_days": 30,
"prefix": "",
"standard_transition_days": 30,
"tags": {}
}
]
| no | +| [lifecycle\_rules](#input\_lifecycle\_rules) | A list of lifecycle rules |
list(object({
prefix = string
enabled = bool
tags = map(string)

enable_glacier_transition = bool
enable_deeparchive_transition = bool
enable_standard_ia_transition = bool
enable_current_object_expiration = bool
enable_noncurrent_version_expiration = bool

abort_incomplete_multipart_upload_days = number
noncurrent_version_glacier_transition_days = number
noncurrent_version_deeparchive_transition_days = number
noncurrent_version_expiration_days = number

standard_transition_days = number
glacier_transition_days = number
deeparchive_transition_days = number
expiration_days = number
}))
|
[
{
"abort_incomplete_multipart_upload_days": 90,
"deeparchive_transition_days": 90,
"enable_current_object_expiration": true,
"enable_deeparchive_transition": false,
"enable_glacier_transition": true,
"enable_noncurrent_version_expiration": true,
"enable_standard_ia_transition": false,
"enabled": false,
"expiration_days": 90,
"glacier_transition_days": 60,
"noncurrent_version_deeparchive_transition_days": 60,
"noncurrent_version_expiration_days": 90,
"noncurrent_version_glacier_transition_days": 30,
"prefix": "",
"standard_transition_days": 30,
"tags": {}
}
]
| no | | [logging](#input\_logging) | Bucket access logging configuration. |
object({
bucket_name = string
prefix = string
})
| `null` | no | | [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a `tag`.
The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no | | [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no | diff --git a/examples/complete/lifecycle.us-east-2.tfvars b/examples/complete/lifecycle.us-east-2.tfvars index c1037646..00deda0f 100644 --- a/examples/complete/lifecycle.us-east-2.tfvars +++ b/examples/complete/lifecycle.us-east-2.tfvars @@ -14,10 +14,11 @@ lifecycle_rules = [ enabled = true tags = { "temp" : "true" } - enable_glacier_transition = false - enable_deeparchive_transition = false - enable_standard_ia_transition = false - enable_current_object_expiration = true + enable_glacier_transition = false + enable_deeparchive_transition = false + enable_standard_ia_transition = false + enable_current_object_expiration = true + enable_noncurrent_version_expiration = true abort_incomplete_multipart_upload_days = null noncurrent_version_glacier_transition_days = 0 @@ -34,10 +35,11 @@ lifecycle_rules = [ enabled = true tags = {} - enable_glacier_transition = false - enable_deeparchive_transition = false - enable_standard_ia_transition = false - enable_current_object_expiration = true + enable_glacier_transition = false + enable_deeparchive_transition = false + enable_standard_ia_transition = false + enable_current_object_expiration = true + enable_noncurrent_version_expiration = true abort_incomplete_multipart_upload_days = 1 noncurrent_version_glacier_transition_days = 0 diff --git a/examples/complete/variables.tf b/examples/complete/variables.tf index 74ceb5a9..0c587d30 100644 --- a/examples/complete/variables.tf +++ b/examples/complete/variables.tf @@ -22,10 +22,11 @@ variable "lifecycle_rules" { enabled = bool tags = map(string) - enable_glacier_transition = bool - enable_deeparchive_transition = bool - enable_standard_ia_transition = bool - enable_current_object_expiration = bool + enable_glacier_transition = bool + enable_deeparchive_transition = bool + enable_standard_ia_transition = bool + enable_current_object_expiration = bool + enable_noncurrent_version_expiration = bool abort_incomplete_multipart_upload_days = number noncurrent_version_glacier_transition_days = number @@ -42,10 +43,11 @@ variable "lifecycle_rules" { prefix = "" tags = {} - enable_glacier_transition = true - enable_deeparchive_transition = false - enable_standard_ia_transition = false - enable_current_object_expiration = true + enable_glacier_transition = true + enable_deeparchive_transition = false + enable_standard_ia_transition = false + enable_current_object_expiration = true + enable_noncurrent_version_expiration = true abort_incomplete_multipart_upload_days = 90 noncurrent_version_glacier_transition_days = 30 diff --git a/main.tf b/main.tf index 1775017f..4604983a 100644 --- a/main.tf +++ b/main.tf @@ -36,8 +36,12 @@ resource "aws_s3_bucket" "default" { tags = lifecycle_rule.value.tags abort_incomplete_multipart_upload_days = lifecycle_rule.value.abort_incomplete_multipart_upload_days - noncurrent_version_expiration { - days = lifecycle_rule.value.noncurrent_version_expiration_days + dynamic "noncurrent_version_expiration" { + for_each = lifecycle_rule.value.enable_noncurrent_version_expiration ? [1] : [] + + content { + days = lifecycle_rule.value.noncurrent_version_expiration_days + } } dynamic "noncurrent_version_transition" { diff --git a/variables.tf b/variables.tf index 631397aa..b93c2c3c 100644 --- a/variables.tf +++ b/variables.tf @@ -85,10 +85,11 @@ variable "lifecycle_rules" { enabled = bool tags = map(string) - enable_glacier_transition = bool - enable_deeparchive_transition = bool - enable_standard_ia_transition = bool - enable_current_object_expiration = bool + enable_glacier_transition = bool + enable_deeparchive_transition = bool + enable_standard_ia_transition = bool + enable_current_object_expiration = bool + enable_noncurrent_version_expiration = bool abort_incomplete_multipart_upload_days = number noncurrent_version_glacier_transition_days = number @@ -105,10 +106,11 @@ variable "lifecycle_rules" { prefix = "" tags = {} - enable_glacier_transition = true - enable_deeparchive_transition = false - enable_standard_ia_transition = false - enable_current_object_expiration = true + enable_glacier_transition = true + enable_deeparchive_transition = false + enable_standard_ia_transition = false + enable_current_object_expiration = true + enable_noncurrent_version_expiration = true abort_incomplete_multipart_upload_days = 90 noncurrent_version_glacier_transition_days = 30