-
Notifications
You must be signed in to change notification settings - Fork 31
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
Add S3 versioning to managed schemas #291
base: master
Are you sure you want to change the base?
Changes from 8 commits
5d345ff
a950ff7
7ec0ae7
c9b2cd3
ea901e4
e7bd8a5
399f011
1a37bae
96f6d9a
90148b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,42 @@ resource "aws_s3_bucket" "apiary_data_bucket" { | |
} | ||
} | ||
|
||
resource "aws_s3_bucket_versioning" "apiary_data_bucket_versioning" { | ||
for_each = { | ||
for schema in local.schemas_info : "${schema["schema_name"]}" => schema | ||
} | ||
bucket = each.value["data_bucket"] | ||
versioning_configuration { | ||
status = lookup(each.value, "s3_versioning_enabled", "Disabled") | ||
} | ||
} | ||
|
||
resource "aws_s3_bucket_lifecycle_configuration" "apiary_data_bucket_versioning_lifecycle" { | ||
for_each = { | ||
for schema in local.schemas_info : "${schema["schema_name"]}" => schema | ||
} | ||
bucket = each.value["data_bucket"] | ||
# Rule enabled when expiration max days is set | ||
rule { | ||
id = "expire-noncurrent-versions-days" | ||
status = lookup(each.value, "s3_versioning_expiration_days", "") != "" && lookup(each.value, "s3_versioning_max_versions_retained", "") == "" ? "Enabled" : "Disabled" | ||
|
||
noncurrent_version_expiration { | ||
noncurrent_days = tonumber(lookup(each.value, "s3_versioning_expiration_days", var.s3_versioning_expiration_days)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question, should we only configure the version expiration? Or should we also configure the max version retain , like 1,2,3 ? If only expiration configured, all older version will be deleted after the days meet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replied privately, conclusion was to start only with days. |
||
} | ||
} | ||
# Rule enabled when expiration max days and versions are set | ||
rule { | ||
id = "expire-noncurrent-versions-number-and-days" | ||
status = lookup(each.value, "s3_versioning_max_versions_retained", "") != "" ? "Enabled" : "Disabled" | ||
|
||
noncurrent_version_expiration { | ||
newer_noncurrent_versions = tonumber(lookup(each.value, "s3_versioning_max_versions_retained", var.s3_versioning_max_versions_retained)) | ||
noncurrent_days = tonumber(lookup(each.value, "s3_versioning_expiration_days", var.s3_versioning_expiration_days)) | ||
} | ||
} | ||
} | ||
|
||
resource "aws_s3_bucket_inventory" "apiary_bucket" { | ||
for_each = var.s3_enable_inventory == true ? { | ||
for schema in local.schemas_info : "${schema["schema_name"]}" => schema | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1095,6 +1095,18 @@ variable "ecs_requires_compatibilities" { | |
default = ["EC2", "FARGATE"] | ||
} | ||
|
||
variable "s3_versioning_expiration_days" { | ||
description = "Number of days (TTL) before objects are expired. Bucket need to have versioning enabled." | ||
type = number | ||
default = 7 | ||
} | ||
|
||
variable "s3_versioning_max_versions_retained" { | ||
description = "Number of noncurrent versions Amazon S3 will retain. Must be a non-zero positive integer. Bucket need to have versioning enabled." | ||
type = number | ||
default = 3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be defaulted off... we don't want to force keeping a number of versions, we want all the versions to be deleted after 7 days by default. If both are set, then it will keep the max versions regardless of the days, which means we will end up keeping some of the deleted data forever (at least this is what I believe I tested and saw that it always retained up to the max versions). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added both options, only days, or days and max_versions. My idea was that if maybe there is a bucket that creates many versions a day, we could reduce costs setting max to 1. Not sure if it could happen, I can delete that part anyway and add it when needed. |
||
} | ||
|
||
variable "hms_ro_tolerations" { | ||
description = <<EOF | ||
Adds a list of tolerations for the HMS readonly pods. For example if you | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't take the default value into account at all does it, the default is ""? So it will only be enabled or disabled depending on what is in the map, and the default value in the var is ignored here. But then the default value IS pulled in in the actual days or versions setting below. I'm not sure I understand... if we override it in the map, then the default will be ignored in both places. If we don't override it in the map, then it will be disabled. There is no case in which the default value will be used?
I guess in the second rule for max versions and days it could be used but only for setting the expiration_days, which only can happen if expiration_days is not set in the map, then it will use the default for it?
I wonder if it is simpler to just leave out the max versions rule completely. I'm not sure we have a case for it anyway. It's an option in the API but I don't think we want to use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, let's do it in that case only days