Skip to content

Commit

Permalink
Add the inteligent tiering configuration to the module
Browse files Browse the repository at this point in the history
  • Loading branch information
bamaralf committed Jun 17, 2022
1 parent 1abb6c4 commit 0c7d472
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 37 deletions.
34 changes: 0 additions & 34 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,41 +1,21 @@
<<<<<<< HEAD
<<<<<<< HEAD

# Created by https://www.gitignore.io/api/terraform
# Edit at https://www.gitignore.io/?templates=terraform

### Terraform ###
# Local .terraform directories
**/.terraform/*

=======
# Local .terraform directories
**/.terraform/*

# Terraform lockfile
.terraform.lock.hcl

>>>>>>> upstream/master
# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log

<<<<<<< HEAD
# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
# .tfvars files are managed as part of configuration and so should be included in
# version control.
#
# example.tfvars
=======
# Exclude all .tfvars files, which are likely to contain sentitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars
>>>>>>> upstream/master

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
Expand All @@ -44,22 +24,8 @@ override.tf.json
*_override.tf
*_override.tf.json

<<<<<<< HEAD
# Include override files you do wish to add to version control using negated pattern
#
# !example_override.tf

# End of https://www.gitignore.io/api/terraform
=======
.terraform
terraform.tfstate
*.tfstate*
terraform.tfvars
>>>>>>> upstream/master
=======
# Ignore CLI configuration files
.terraformrc
terraform.rc

*.zip
>>>>>>> upstream/master
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ No modules.
| [aws_s3_bucket_accelerate_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_accelerate_configuration) | resource |
| [aws_s3_bucket_acl.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_acl) | resource |
| [aws_s3_bucket_cors_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_cors_configuration) | resource |
| [aws_s3_bucket_intelligent_tiering_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_intelligent_tiering_configuration) | resource |
| [aws_s3_bucket_lifecycle_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_lifecycle_configuration) | resource |
| [aws_s3_bucket_logging.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_logging) | resource |
| [aws_s3_bucket_object_lock_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_object_lock_configuration) | resource |
Expand Down Expand Up @@ -180,6 +181,7 @@ No modules.
| <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 |
| <a name="input_grant"></a> [grant](#input\_grant) | An ACL policy grant. Conflicts with `acl` | `any` | `[]` | no |
| <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 |
| <a name="input_intelligent_tiering_config"></a> [intelligent\_tiering\_config](#input\_intelligent\_tiering\_config) | Map containing inteligent tiering config encryption configuration. | `any` | `{}` | no |
| <a name="input_lifecycle_rule"></a> [lifecycle\_rule](#input\_lifecycle\_rule) | List of maps containing configuration of object lifecycle management. | `any` | `[]` | no |
| <a name="input_logging"></a> [logging](#input\_logging) | Map containing access bucket logging configuration. | `map(string)` | `{}` | no |
| <a name="input_object_lock_configuration"></a> [object\_lock\_configuration](#input\_object\_lock\_configuration) | Map containing S3 object locking configuration. | `any` | `{}` | no |
Expand Down
25 changes: 25 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,31 @@ module "s3_bucket" {
Owner = "Anton"
}

intelligent_tiering_config = {
general = {
status = "Enabled"
filter = {
prefix = "/"
tags = { Environment = "dev" }
}
tiering = {
"ARCHIVE_ACCESS" = {
days = 180
}
}
},
documents = {
status = false
filter = {
prefix = "documents/"
}
tiering = {
"ARCHIVE_ACCESS" = {
days = 125
}
}
}
}
# Note: Object Lock configuration can be enabled only on new buckets
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_object_lock_configuration
object_lock_enabled = true
Expand Down
34 changes: 31 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ locals {
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

# Variables with type `any` should be jsonencode()'d when value is coming from Terragrunt
grants = try(jsondecode(var.grant), var.grant)
cors_rules = try(jsondecode(var.cors_rule), var.cors_rule)
lifecycle_rules = try(jsondecode(var.lifecycle_rule), var.lifecycle_rule)
grants = try(jsondecode(var.grant), var.grant)
cors_rules = try(jsondecode(var.cors_rule), var.cors_rule)
lifecycle_rules = try(jsondecode(var.lifecycle_rule), var.lifecycle_rule)
intelligent_tiering_config = try(jsondecode(var.intelligent_tiering_config), var.intelligent_tiering_config)
}

resource "aws_s3_bucket" "this" {
Expand Down Expand Up @@ -707,3 +708,30 @@ resource "aws_s3_bucket_ownership_controls" "this" {
aws_s3_bucket.this
]
}

resource "aws_s3_bucket_intelligent_tiering_configuration" "this" {
for_each = local.create_bucket ? local.intelligent_tiering_config : {}

name = each.key
bucket = aws_s3_bucket.this[0].id
status = each.value.status || each.value.status == "Enabled" ? "Enabled" : "Disabled"

dynamic "filter" {
for_each = each.value.filter

content {
prefix = try(filter.value.prefix, null)
tags = try(filter.value.tags, null)
}
}

dynamic "tiering" {
for_each = each.value.tiering

content {
access_tier = tiering.key
days = tiering.value.days
}
}

}
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,9 @@ variable "putin_khuylo" {
type = bool
default = true
}

variable "intelligent_tiering_config" {
description = "Map containing inteligent tiering config encryption configuration."
type = any
default = {}
}
1 change: 1 addition & 0 deletions wrappers/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ module "wrapper" {
control_object_ownership = try(each.value.control_object_ownership, var.defaults.control_object_ownership, false)
object_ownership = try(each.value.object_ownership, var.defaults.object_ownership, "ObjectWriter")
putin_khuylo = try(each.value.putin_khuylo, var.defaults.putin_khuylo, true)
intelligent_tiering_config = try(each.value.intelligent_tiering_config, var.defaults.intelligent_tiering_config, {})
}

0 comments on commit 0c7d472

Please sign in to comment.