Skip to content

Commit 73c48d6

Browse files
authored
feat: Add the intelligent tiering configuration (#167)
1 parent 8609195 commit 73c48d6

File tree

5 files changed

+72
-3
lines changed

5 files changed

+72
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ No modules.
138138
| [aws_s3_bucket_accelerate_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_accelerate_configuration) | resource |
139139
| [aws_s3_bucket_acl.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_acl) | resource |
140140
| [aws_s3_bucket_cors_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_cors_configuration) | resource |
141+
| [aws_s3_bucket_intelligent_tiering_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_intelligent_tiering_configuration) | resource |
141142
| [aws_s3_bucket_lifecycle_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_lifecycle_configuration) | resource |
142143
| [aws_s3_bucket_logging.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_logging) | resource |
143144
| [aws_s3_bucket_object_lock_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_object_lock_configuration) | resource |
@@ -180,6 +181,7 @@ No modules.
180181
| <a name="input_force_destroy"></a> [force\_destroy](#input\_force\_destroy) | (Optional, Default:false ) A boolean that indicates all objects should be deleted from the bucket so that the bucket can be destroyed without error. These objects are not recoverable. | `bool` | `false` | no |
181182
| <a name="input_grant"></a> [grant](#input\_grant) | An ACL policy grant. Conflicts with `acl` | `any` | `[]` | no |
182183
| <a name="input_ignore_public_acls"></a> [ignore\_public\_acls](#input\_ignore\_public\_acls) | Whether Amazon S3 should ignore public ACLs for this bucket. | `bool` | `false` | no |
184+
| <a name="input_intelligent_tiering"></a> [intelligent\_tiering](#input\_intelligent\_tiering) | Map containing intelligent tiering configuration. | `any` | `{}` | no |
183185
| <a name="input_lifecycle_rule"></a> [lifecycle\_rule](#input\_lifecycle\_rule) | List of maps containing configuration of object lifecycle management. | `any` | `[]` | no |
184186
| <a name="input_logging"></a> [logging](#input\_logging) | Map containing access bucket logging configuration. | `map(string)` | `{}` | no |
185187
| <a name="input_object_lock_configuration"></a> [object\_lock\_configuration](#input\_object\_lock\_configuration) | Map containing S3 object locking configuration. | `any` | `{}` | no |

examples/complete/main.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,35 @@ module "s3_bucket" {
293293
}
294294
},
295295
]
296+
297+
intelligent_tiering = {
298+
general = {
299+
status = "Enabled"
300+
filter = {
301+
prefix = "/"
302+
tags = {
303+
Environment = "dev"
304+
}
305+
}
306+
tiering = {
307+
ARCHIVE_ACCESS = {
308+
days = 180
309+
}
310+
}
311+
},
312+
documents = {
313+
status = false
314+
filter = {
315+
prefix = "documents/"
316+
}
317+
tiering = {
318+
ARCHIVE_ACCESS = {
319+
days = 125
320+
}
321+
DEEP_ARCHIVE_ACCESS = {
322+
days = 200
323+
}
324+
}
325+
}
326+
}
296327
}

main.tf

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ locals {
66
attach_policy = var.attach_require_latest_tls_policy || var.attach_elb_log_delivery_policy || var.attach_lb_log_delivery_policy || var.attach_deny_insecure_transport_policy || var.attach_policy
77

88
# Variables with type `any` should be jsonencode()'d when value is coming from Terragrunt
9-
grants = try(jsondecode(var.grant), var.grant)
10-
cors_rules = try(jsondecode(var.cors_rule), var.cors_rule)
11-
lifecycle_rules = try(jsondecode(var.lifecycle_rule), var.lifecycle_rule)
9+
grants = try(jsondecode(var.grant), var.grant)
10+
cors_rules = try(jsondecode(var.cors_rule), var.cors_rule)
11+
lifecycle_rules = try(jsondecode(var.lifecycle_rule), var.lifecycle_rule)
12+
intelligent_tiering = try(jsondecode(var.intelligent_tiering), var.intelligent_tiering)
1213
}
1314

1415
resource "aws_s3_bucket" "this" {
@@ -707,3 +708,31 @@ resource "aws_s3_bucket_ownership_controls" "this" {
707708
aws_s3_bucket.this
708709
]
709710
}
711+
712+
resource "aws_s3_bucket_intelligent_tiering_configuration" "this" {
713+
for_each = { for k, v in local.intelligent_tiering : k => v if local.create_bucket }
714+
715+
name = each.key
716+
bucket = aws_s3_bucket.this[0].id
717+
status = try(tobool(each.value.status) ? "Enabled" : "Disabled", title(lower(each.value.status)), null)
718+
719+
# Max 1 block - filter
720+
dynamic "filter" {
721+
for_each = length(try(flatten([each.value.filter]), [])) == 0 ? [] : [true]
722+
723+
content {
724+
prefix = try(each.value.filter.prefix, null)
725+
tags = try(each.value.filter.tags, null)
726+
}
727+
}
728+
729+
dynamic "tiering" {
730+
for_each = each.value.tiering
731+
732+
content {
733+
access_tier = tiering.key
734+
days = tiering.value.days
735+
}
736+
}
737+
738+
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ variable "server_side_encryption_configuration" {
148148
default = {}
149149
}
150150

151+
variable "intelligent_tiering" {
152+
description = "Map containing intelligent tiering configuration."
153+
type = any
154+
default = {}
155+
}
156+
151157
variable "object_lock_configuration" {
152158
description = "Map containing S3 object locking configuration."
153159
type = any

wrappers/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module "wrapper" {
2828
lifecycle_rule = try(each.value.lifecycle_rule, var.defaults.lifecycle_rule, [])
2929
replication_configuration = try(each.value.replication_configuration, var.defaults.replication_configuration, {})
3030
server_side_encryption_configuration = try(each.value.server_side_encryption_configuration, var.defaults.server_side_encryption_configuration, {})
31+
intelligent_tiering = try(each.value.intelligent_tiering, var.defaults.intelligent_tiering, {})
3132
object_lock_configuration = try(each.value.object_lock_configuration, var.defaults.object_lock_configuration, {})
3233
object_lock_enabled = try(each.value.object_lock_enabled, var.defaults.object_lock_enabled, false)
3334
block_public_acls = try(each.value.block_public_acls, var.defaults.block_public_acls, false)

0 commit comments

Comments
 (0)