Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add the inteligent tiering configuration #166

Closed
wants to merge 12 commits into from

Conversation

bamaralf
Copy link
Contributor

@bamaralf bamaralf commented Jun 16, 2022

Description

This pull request adds the option of managing the bucket intelligent tiering configuration by passing a map of objects to this module. This map of objects encapsulates the configuration options from this resource: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_intelligent_tiering_configuration

Motivation and Context

Intelligent tiering configuration can optimize the costs of the S3 buckets infrastructure and the changes in this pull request make these configurations available from the module.

Breaking Changes

None

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects
  • I have executed pre-commit run -a on my pull request

@bamaralf bamaralf changed the title Add intelligent tiering configuration feat/intelligent-tiering-configuration Jun 16, 2022
@bamaralf bamaralf changed the title feat/intelligent-tiering-configuration feat: add the inteligent tiering configuration Jun 16, 2022
@bamaralf bamaralf changed the title feat: add the inteligent tiering configuration feat: Add the inteligent tiering configuration Jun 16, 2022
@bamaralf bamaralf force-pushed the master branch 2 times, most recently from f442a08 to 8a673bf Compare June 16, 2022 18:48
@bamaralf bamaralf marked this pull request as ready for review June 16, 2022 19:02
Copy link
Member

@antonbabenko antonbabenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. Could you please try to implement such a feature as close to the rest of the code in this module (no need for a new module, var.intelligent_tiering_config should be map(any) or any, do not use module experiments, defaults(), optional())?

variables.tf Outdated
@@ -4,6 +4,24 @@ variable "create_bucket" {
default = true
}

variable "intelligent_tiering" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this variable to the end of this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @antonbabenko. I pushed the suggested changes

@bamaralf bamaralf marked this pull request as draft June 16, 2022 19:59
@bamaralf bamaralf force-pushed the master branch 2 times, most recently from e6b4ed2 to 6a1087f Compare June 17, 2022 02:41
@bamaralf bamaralf marked this pull request as ready for review June 17, 2022 02:44
@bamaralf bamaralf requested a review from antonbabenko June 17, 2022 02:44
main.tf Outdated
@@ -707,3 +712,25 @@ resource "aws_s3_bucket_ownership_controls" "this" {
aws_s3_bucket.this
]
}

resource "aws_s3_bucket_intelligent_tiering_configuration" "tiering_conf" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
resource "aws_s3_bucket_intelligent_tiering_configuration" "tiering_conf" {
resource "aws_s3_bucket_intelligent_tiering_configuration" "this" {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resource was renamed

main.tf Outdated
@@ -9,6 +9,11 @@ locals {
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 = var.intelligent_tiering_config == null ? null : defaults(var.intelligent_tiering_config, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
intelligent_tiering_config = var.intelligent_tiering_config == null ? null : defaults(var.intelligent_tiering_config, {
intelligent_tiering_config = try(jsondecode(var.intelligent_tiering_config), var.intelligent_tiering_config)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop the magic with defaults()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

main.tf Outdated
@@ -707,3 +712,25 @@ resource "aws_s3_bucket_ownership_controls" "this" {
aws_s3_bucket.this
]
}

resource "aws_s3_bucket_intelligent_tiering_configuration" "tiering_conf" {
for_each = local.intelligent_tiering_config
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add new line after for_each

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such for_each should respect the value of local.create_bucket as in other resources.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I updated the for_each loop

main.tf Outdated
bucket = aws_s3_bucket.this[0].id
status = each.value.status

filter {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filter is optional according to the docs. Same as prefix and tags in it. Update the code to use dynamic. See other resources for examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the config to a dynamic block

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can filter be one or multiple blocks? Now it looks like multiple, but according to the docs it should be zero-or-one? Please update as in other resource (... ? [true] : [])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change is in place

main.tf Outdated
for_each = each.value.tiering

content {
access_tier = try(tiering.key, null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

access_tier and days are required, so there is no need to wrap values with try()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I removed the try()

variables.tf Outdated
@@ -201,3 +201,22 @@ variable "putin_khuylo" {
type = bool
default = true
}

variable "intelligent_tiering_config" {
description = <<EOS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make the description as a string (not heredoc), no link to the documentation, and no comments for the type. See line 146, for example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, the description was updated

variables.tf Outdated
# days = number
# }))
# }))
default = null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
default = null
default = {}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change is in place

main.tf Outdated
for_each = local.intelligent_tiering_config
name = each.key
bucket = aws_s3_bucket.this[0].id
status = each.value.status
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make status to accept boolean true / false also. See other resources in this module.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change is in place

@bamaralf bamaralf marked this pull request as draft June 17, 2022 12:26
@bamaralf bamaralf force-pushed the master branch 4 times, most recently from 914dca8 to 0c7d472 Compare June 17, 2022 12:39
@bamaralf bamaralf requested a review from antonbabenko June 17, 2022 12:43
@bamaralf bamaralf marked this pull request as ready for review June 17, 2022 12:44
@antonbabenko
Copy link
Member

This issue has been resolved in version 3.3.0 🎉

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants