Skip to content

Commit 04c6fb9

Browse files
authored
feat: Add support for lifecycle rules (#35)
* Add lifecycle rules feature on scaleway_object_bucket resource * Fix transition and expiration blocks [X] terraform fmt applied [X] terraform docs applied
1 parent e6b5121 commit 04c6fb9

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ module "my_bucket" {
4242
| <a name="input_name"></a> [name](#input_name) | Name of the bucket. | `string` | n/a | yes |
4343
| <a name="input_acl"></a> [acl](#input_acl) | Canned ACL to apply to the bucket. See AWS (documentation)[https://docs.aws.amazon.com/AmazonS3/latest/userguide/acl-overview.html#canned-acl] for more information. | `string` | `"private"` | no |
4444
| <a name="input_force_destroy"></a> [force_destroy](#input_force_destroy) | Enable deletion of objects in bucket before destroying, locked objects or under legal hold are also deleted and not recoverable. | `bool` | `false` | no |
45+
| <a name="input_lifecycle_rules"></a> [lifecycle_rules](#input_lifecycle_rules) | Define bucket lifecycle configuration | ```list(object({ id = string prefix = optional(string) tags = optional(map(string)) enabled = bool abort_incomplete_multipart_upload_days = optional(number) expiration = optional(object({ days = string })) transition = optional(object({ days = number storage_class = string })) }))``` | `[]` | no |
4546
| <a name="input_policy"></a> [policy](#input_policy) | Policy document. For more information about building AWS IAM policy documents with Terraform, see the [AWS IAM Policy Document Guide](https://learn.hashicorp.com/tutorials/terraform/aws-iam-policy). | ```object({ Version = string, Id = string Statement = list(object({ Sid = string Effect = string Principal = string Action = list(string) Resource = list(string) })) })``` | `null` | no |
4647
| <a name="input_project_id"></a> [project_id](#input_project_id) | ID of the project the bucket is associated with. If null, ressources will be created in the default project associated with the key. | `string` | `null` | no |
4748
| <a name="input_region"></a> [region](#input_region) | Region in which the bucket should be created. Ressource will be created in the region set at the provider level if null. | `string` | `null` | no |

main.tf

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,32 @@ resource "scaleway_object_bucket" "this" {
77
project_id = var.project_id
88
tags = zipmap(var.tags, var.tags)
99

10+
dynamic "lifecycle_rule" {
11+
for_each = length(var.lifecycle_rules) == 0 ? [] : var.lifecycle_rules
12+
content {
13+
id = lifecycle_rule.value["id"]
14+
prefix = lifecycle_rule.value["prefix"]
15+
tags = lifecycle_rule.value["tags"]
16+
enabled = lifecycle_rule.value["enabled"]
17+
abort_incomplete_multipart_upload_days = lifecycle_rule.value["abort_incomplete_multipart_upload_days"]
18+
19+
dynamic "expiration" {
20+
for_each = lifecycle_rule.value["expiration"] == null ? [] : [lifecycle_rule.value["expiration"]]
21+
content {
22+
days = expiration.value["days"]
23+
}
24+
}
25+
26+
dynamic "transition" {
27+
for_each = lifecycle_rule.value["transition"] == null ? [] : [lifecycle_rule.value["transition"]]
28+
content {
29+
days = transition.value["days"]
30+
storage_class = transition.value["storage_class"]
31+
}
32+
}
33+
}
34+
}
35+
1036
versioning {
1137
enabled = var.versioning_enabled
1238
}

variables.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,25 @@ variable "force_destroy" {
1010
default = false
1111
}
1212

13+
variable "lifecycle_rules" {
14+
description = "Define bucket lifecycle configuration"
15+
type = list(object({
16+
id = string
17+
prefix = optional(string)
18+
tags = optional(map(string))
19+
enabled = bool
20+
abort_incomplete_multipart_upload_days = optional(number)
21+
expiration = optional(object({
22+
days = string
23+
}))
24+
transition = optional(object({
25+
days = number
26+
storage_class = string
27+
}))
28+
}))
29+
default = []
30+
}
31+
1332
variable "name" {
1433
description = "Name of the bucket."
1534
type = string

0 commit comments

Comments
 (0)