-
Notifications
You must be signed in to change notification settings - Fork 3
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 lifecycle rules feature on scaleway_object_bucket resource #35
Add lifecycle rules feature on scaleway_object_bucket resource #35
Conversation
4efd64c
to
81315fb
Compare
[X] terraform fmt applied [X] terraform docs applied
81315fb
to
fb186ef
Compare
@jgalais Awesome! However I made some test on my side and it appears we can only set 1 expiration block by rule. The following code throws an error during plan: lifecycle_rules = [
{
id = "lifecycle_expiration_test"
enabled = false
expiration = [
{
days = 31
},
{
days = 365
}
]
}, Also, we can only set 1 transition per rule. The following code plans ok, but get an HTTP 501 from Scaleway API during apply: lifecycle_rules = [
{
id = "lifecycle_transition"
enabled = false
transition = [
{
days = 30
storage_class = "ONEZONE_IA"
},
{
days = 360
storage_class = "GLACIER"
}
]
},
] Do you think you could change your PR in order to reflect this? |
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.
Bucket lifecycle can only contains 1 expiration and/or 1 transition per rules.
Hello, I checked that. The problem is complex:
The "expiration" and "transition" are terraform blocks. The feature that allow to reproduce multiple time a terraform block is called "Dynamic-blocks (https://developer.hashicorp.com/terraform/language/expressions/dynamic-blocks).
"Expiration" and "Transition" blocks can have only one value. Terraform syntax is ok but Scaleway API doesn't allow that. I think that we must to keep like that because:
I have an example with this behavior. The lifecycle_rules on AWS S3 buckets. The only difference with Scaleway and AWS on this case is that the block "expiration" AND "transition" accept only one value for Scaleway where in AWS only the block "expiration" accept only one value. Link: https://github.com/terraform-aws-modules/terraform-aws-s3-bucket/blob/master/main.tf#L263 Expiration block:
Transition block:
Regards, |
You can still use dynamic blocks for this. For the transition, you could:
variable "lifecycle_rules" {
description = "Define bucket lifecycle configuration"
type = list(object({
id = string
...
transition = optional(object({
days = number
storage_class = string
}))
...
}))
default = []
}
resource "scaleway_object_bucket" "this" {
...
dynamic "lifecycle_rule" {
for_each = length(var.lifecycle_rules) == 0 ? [] : var.lifecycle_rules
content {
...
dynamic "transition" {
for_each = lifecycle_rule.value["transition"] == null ? [] : [lifecycle_rule.value["transition"]]
content {
days = transition.value["days"]
storage_class = transition.value["storage_class"]
}
}
}
}
...
} You can also use this method for setting the expiration days. |
I done that. |
04c6fb9
into
scaleway-terraform-modules:main
@jgalais Thanks! |
Hello,
I added lifecycle support on this module.
I tested this feature with the next configuration inside this module:
Additional information:
[X] terraform fmt applied
[X] terraform docs applied
Regards,
jgalais