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 16, 2022
1 parent 1abb6c4 commit e961f97
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 35 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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ Users of Terragrunt can achieve similar results by using modules provided in the

## Modules

No modules.
| Name | Source | Version |
|------|--------|---------|
| <a name="module_intelligent_tiering"></a> [intelligent\_tiering](#module\_intelligent\_tiering) | ./modules/tiering | n/a |

## Resources

Expand Down Expand Up @@ -180,6 +182,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"></a> [intelligent\_tiering](#input\_intelligent\_tiering) | Each element of map of objects represents a intelligent tiering config to be added to a S3 bucket.<br>(https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_intelligent_tiering_configuration) | <pre>map(object({<br> status = string<br> filter = object({<br> prefix = string<br> tags = map(string)<br> })<br> tiering = map(object({<br> days = number<br> }))<br> }))</pre> | `null` | 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
26 changes: 26 additions & 0 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,32 @@ module "s3_bucket" {
Owner = "Anton"
}

intelligent_tiering = {
general = {
status = "Enabled"
filter = {
prefix = "/"
tags = {}
}
tiering = {
"ARCHIVE_ACCESS" = {
days = 180
}
}
},
documents = {
status = "Disabled"
filter = {
prefix = "documents/"
tags = {}
}
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
14 changes: 14 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -707,3 +707,17 @@ resource "aws_s3_bucket_ownership_controls" "this" {
aws_s3_bucket.this
]
}

module "intelligent_tiering" {
for_each = var.intelligent_tiering
source = "./modules/tiering"

intelligent_tiering_config = {
(each.key) = {
bucket = aws_s3_bucket.this[0].id
status = try(each.value.status, "Enabled")
filter = each.value.filter
tiering = each.value.tiering
}
}
}
32 changes: 32 additions & 0 deletions modules/tiering/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.74 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.74 |

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [aws_s3_bucket_intelligent_tiering_configuration.tiering_conf](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_intelligent_tiering_configuration) | resource |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_intelligent_tiering"></a> [intelligent\_tiering](#input\_intelligent\_tiering) | Each element of map of objects represents a intelligent tiering config to be added to a S3 bucket.<br>(https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_intelligent_tiering_configuration) | <pre>map(object({<br> bucket = string<br> status = string<br> filter = optional(object({<br> prefix = string<br> tags = map(string)<br> }))<br> tiering = optional(map(object({<br> access_tier = string<br> days = number<br> })))<br> }))</pre> | `null` | no |

## Outputs

No outputs.
7 changes: 7 additions & 0 deletions modules/tiering/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
locals {
intelligent_tiering_config = var.intelligent_tiering_config == null ? null : defaults(var.intelligent_tiering_config, {
status = "Enabled"
filter = {}
tiering = {}
})
}
21 changes: 21 additions & 0 deletions modules/tiering/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
resource "aws_s3_bucket_intelligent_tiering_configuration" "tiering_conf" {
for_each = local.intelligent_tiering_config
name = each.key
bucket = each.value.bucket
status = each.value.status

filter {
prefix = try(each.value.filter["prefix"], null)
tags = try(each.value.filter["tags"], null)
}

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

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

}
Empty file added modules/tiering/outputs.tf
Empty file.
18 changes: 18 additions & 0 deletions modules/tiering/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
variable "intelligent_tiering_config" {
description = <<EOS
Each element of map of objects represents a intelligent tiering config to be added to a S3 bucket.
(https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_intelligent_tiering_configuration)
EOS
type = map(object({
bucket = string
status = string
filter = optional(object({
prefix = string
tags = map(string)
}))
tiering = optional(map(object({
days = number
})))
}))
default = null
}
11 changes: 11 additions & 0 deletions modules/tiering/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
terraform {
experiments = [module_variable_optional_attrs]
required_version = ">= 0.13.1"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 3.74"
}
}
}
18 changes: 18 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,21 @@ variable "putin_khuylo" {
type = bool
default = true
}

variable "intelligent_tiering" {
description = <<EOS
Each element of map of objects represents a intelligent tiering config to be added to a S3 bucket.
(https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_intelligent_tiering_configuration)
EOS
type = map(object({
status = string
filter = object({
prefix = string
tags = map(string)
})
tiering = map(object({
days = number
}))
}))
default = null
}
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 = try(each.value.intelligent_tiering, var.defaults.intelligent_tiering, null)
}

0 comments on commit e961f97

Please sign in to comment.