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

Add lifecycle rules feature on scaleway_object_bucket resource #35

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(object({ days = string })) transition = optional(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 = length(var.lifecycle_rules) == 0 ? [] : var.lifecycle_rules
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"] == null ? [] : [lifecycle_rule.value["expiration"]]
content {
days = expiration.value["days"]
}
}

dynamic "transition" {
for_each = lifecycle_rule.value["transition"] == null ? [] : [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(object({
days = string
}))
transition = optional(object({
days = number
storage_class = string
}))
}))
default = []
}

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