Skip to content

Commit 00667da

Browse files
authored
Merge pull request #19 from rhythmictech/lifecycle-fixes
Fix lifecycle rule drift
2 parents a77fca3 + 481f583 commit 00667da

File tree

8 files changed

+49
-64
lines changed

8 files changed

+49
-64
lines changed

.terraform.lock.hcl

-27
This file was deleted.

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ module "cloudtrail-logging" {
4848
| Name | Version |
4949
|------|---------|
5050
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.3 |
51-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4 |
51+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.70.0, < 6.0.0 |
5252

5353
## Providers
5454

5555
| Name | Version |
5656
|------|---------|
57-
| <a name="provider_aws"></a> [aws](#provider\_aws) | 4.48.0 |
57+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.70.0, < 6.0.0 |
5858

5959
## Modules
6060

@@ -82,7 +82,8 @@ No modules.
8282
| <a name="input_bucket_name"></a> [bucket\_name](#input\_bucket\_name) | Name to apply to bucket (use `bucket_name` or `bucket_suffix`) | `string` | `null` | no |
8383
| <a name="input_bucket_suffix"></a> [bucket\_suffix](#input\_bucket\_suffix) | Suffix to apply to the bucket (use `bucket_name` or `bucket_suffix`). When using `bucket_suffix`, the bucket name will be `[account_id]-[region]-s3logging-[bucket_suffix].` | `string` | `"default"` | no |
8484
| <a name="input_kms_key_id"></a> [kms\_key\_id](#input\_kms\_key\_id) | KMS key to encrypt bucket with. | `string` | `null` | no |
85-
| <a name="input_lifecycle_rules"></a> [lifecycle\_rules](#input\_lifecycle\_rules) | lifecycle rules to apply to the bucket | <pre>list(object(<br> {<br> id = string<br> enabled = optional(bool, true)<br> expiration = optional(number)<br> prefix = optional(number)<br> noncurrent_version_expiration = optional(number)<br> transition = optional(list(object({<br> days = number<br> storage_class = string<br> })))<br> }))</pre> | <pre>[<br> {<br> "id": "expire-noncurrent-objects-after-ninety-days",<br> "noncurrent_version_expiration": 90<br> },<br> {<br> "id": "transition-to-IA-after-30-days",<br> "transition": [<br> {<br> "days": 30,<br> "storage_class": "STANDARD_IA"<br> }<br> ]<br> },<br> {<br> "expiration": 2557,<br> "id": "delete-after-seven-years"<br> }<br>]</pre> | no |
85+
| <a name="input_lifecycle_rules"></a> [lifecycle\_rules](#input\_lifecycle\_rules) | lifecycle rules to apply to the bucket | <pre>list(object(<br> {<br> id = string<br> enabled = optional(bool, true)<br> expiration = optional(number)<br> prefix = optional(string)<br> noncurrent_version_expiration = optional(number)<br> transition = optional(list(object({<br> days = number<br> storage_class = string<br> })))<br> }))</pre> | <pre>[<br> {<br> "id": "expire-noncurrent-objects-after-ninety-days",<br> "noncurrent_version_expiration": 90<br> },<br> {<br> "id": "transition-to-IA-after-30-days",<br> "transition": [<br> {<br> "days": 30,<br> "storage_class": "STANDARD_IA"<br> }<br> ]<br> },<br> {<br> "expiration": 2557,<br> "id": "delete-after-seven-years"<br> }<br>]</pre> | no |
86+
| <a name="input_lifecycle_transition_default_minimum_object_size"></a> [lifecycle\_transition\_default\_minimum\_object\_size](#input\_lifecycle\_transition\_default\_minimum\_object\_size) | The default minimum object size behavior applied to the lifecycle configuration | `string` | `"varies_by_storage_class"` | no |
8687
| <a name="input_object_ownership"></a> [object\_ownership](#input\_object\_ownership) | Specifies S3 object ownership control. Defaults to BucketOwnerPreferred for backwards-compatibility. Recommended value is BucketOwnerEnforced. | `string` | `"BucketOwnerEnforced"` | no |
8788
| <a name="input_tags"></a> [tags](#input\_tags) | Tags to add to supported resources | `map(string)` | `{}` | no |
8889
| <a name="input_versioning_enabled"></a> [versioning\_enabled](#input\_versioning\_enabled) | Whether or not to use versioning on the bucket. This can be useful for audit purposes since objects in a logging bucket should not be updated. | `bool` | `true` | no |

examples/basic/.terraform.lock.hcl

-25
This file was deleted.

examples/basic/versions.tf

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.3"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 5.70.0, < 6.0.0"
8+
}
9+
}
10+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
required_version = ">= 1.3"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 5.70.0, < 6.0.0"
8+
}
9+
}
10+
}

main.tf

+12-7
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ resource "aws_s3_bucket_acl" "this" {
2929
}
3030

3131
resource "aws_s3_bucket_lifecycle_configuration" "this" {
32-
count = var.lifecycle_rules == null ? 0 : 1
32+
count = length(var.lifecycle_rules) > 0 ? 1 : 0
3333

34-
bucket = aws_s3_bucket.this.id
34+
bucket = aws_s3_bucket.this.id
35+
transition_default_minimum_object_size = var.lifecycle_transition_default_minimum_object_size
3536

3637
dynamic "rule" {
3738
iterator = rule
@@ -42,18 +43,22 @@ resource "aws_s3_bucket_lifecycle_configuration" "this" {
4243
status = rule.value.enabled ? "Enabled" : "Disabled"
4344

4445
filter {
45-
prefix = lookup(rule.value, "prefix", null)
46+
prefix = try(rule.value.prefix, null)
4647
}
4748

48-
expiration {
49-
days = lookup(rule.value, "expiration", 2147483647)
49+
dynamic "expiration" {
50+
for_each = rule.value.expiration != null ? [1] : [0]
51+
52+
content {
53+
days = rule.value.expiration
54+
}
5055
}
5156

5257
dynamic "noncurrent_version_expiration" {
53-
for_each = lookup(rule.value, "noncurrent_version_expiration", null) != null ? [1] : []
58+
for_each = rule.value.noncurrent_version_expiration != null ? [1] : []
5459

5560
content {
56-
noncurrent_days = lookup(rule.value, "noncurrent_version_expiration", null)
61+
noncurrent_days = rule.value.noncurrent_version_expiration
5762
}
5863
}
5964

variables.tf

+8-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ variable "lifecycle_rules" {
4242
id = string
4343
enabled = optional(bool, true)
4444
expiration = optional(number)
45-
prefix = optional(number)
45+
prefix = optional(string)
4646
noncurrent_version_expiration = optional(number)
4747
transition = optional(list(object({
4848
days = number
@@ -51,9 +51,16 @@ variable "lifecycle_rules" {
5151
}))
5252
}
5353

54+
variable "lifecycle_transition_default_minimum_object_size" {
55+
default = "varies_by_storage_class"
56+
description = "The default minimum object size behavior applied to the lifecycle configuration"
57+
type = string
58+
}
59+
5460
variable "object_ownership" {
5561
default = "BucketOwnerEnforced"
5662
description = "Specifies S3 object ownership control. Defaults to BucketOwnerPreferred for backwards-compatibility. Recommended value is BucketOwnerEnforced."
63+
type = string
5764
}
5865

5966
variable "tags" {

versions.tf

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
terraform {
22
required_version = ">= 1.3"
3+
34
required_providers {
4-
aws = ">= 4"
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 5.70.0, < 6.0.0"
8+
}
59
}
610
}

0 commit comments

Comments
 (0)