Skip to content

Commit

Permalink
Add lifecycle rules feature on scaleway_object_bucket resource
Browse files Browse the repository at this point in the history
[X] terraform fmt applied
[X] terraform docs applied
  • Loading branch information
jgalais committed Apr 9, 2024
1 parent e6b5121 commit 4efd64c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ module "my_bucket" {
| <a name="input_name"></a> [name](#input_name) | Name of the bucket. | `string` | n/a | yes |
| <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 |
| <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 |
| <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(list(object({ days = string })), []) transition = optional(list(object({ days = number storage_class = string })), []) }))``` | `[]` | no |
| <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 |
| <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 |
| <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 |
Expand Down
26 changes: 26 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@ resource "scaleway_object_bucket" "this" {
project_id = var.project_id
tags = zipmap(var.tags, var.tags)

dynamic "lifecycle_rule" {
for_each = var.lifecycle_rules != [] ? var.lifecycle_rules : []

Check warning on line 11 in main.tf

View workflow job for this annotation

GitHub Actions / check_tf / Linting

Comparing a collection with an empty list is invalid. To detect an empty collection, check its length.
content {
id = lifecycle_rule.value["id"]
prefix = lifecycle_rule.value["prefix"]
tags = lifecycle_rule.value["tags"]
enabled = lifecycle_rule.value["enabled"]
abort_incomplete_multipart_upload_days = lifecycle_rule.value["abort_incomplete_multipart_upload_days"]

dynamic "expiration" {
for_each = lifecycle_rule.value["expiration"]
content {
days = expiration.value["days"]
}
}

dynamic "transition" {
for_each = lifecycle_rule.value["transition"]
content {
days = transition.value["days"]
storage_class = transition.value["storage_class"]
}
}
}
}

versioning {
enabled = var.versioning_enabled
}
Expand Down
19 changes: 19 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@ variable "force_destroy" {
default = false
}

variable "lifecycle_rules" {
description = "Define bucket lifecycle configuration"
type = list(object({
id = string
prefix = optional(string)
tags = optional(map(string))
enabled = bool
abort_incomplete_multipart_upload_days = optional(number)
expiration = optional(list(object({
days = string
})), [])
transition = optional(list(object({
days = number
storage_class = string
})), [])
}))
default = []
}

variable "name" {
description = "Name of the bucket."
type = string
Expand Down

0 comments on commit 4efd64c

Please sign in to comment.