Skip to content

Commit c666667

Browse files
cichy1173benoit-garcia
authored andcommitted
fix: versioning_enabled is working now
1 parent f46d5ef commit c666667

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module "my_bucket" {
4848
| <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 |
4949
| <a name="input_tags"></a> [tags](#input_tags) | A list of tags for the bucket. As the Scaleway console does not support key/value tags, tags are written with the format value/value. | `list(string)` | `[]` | no |
5050
| <a name="input_versioning_enabled"></a> [versioning_enabled](#input_versioning_enabled) | Enable versioning. Once you version-enable a bucket, it can never return to an unversioned state. You can, however, suspend versioning on that bucket. | `bool` | `false` | no |
51-
| <a name="input_versioning_lock_configuration"></a> [versioning_lock_configuration](#input_versioning_lock_configuration) | Specifies the Object Lock rule for the bucket. Requires versioning. | ```object({ mode = string, days = optional(number), years = optional(number), })``` | ```{ "days": null, "mode": "GOVERNANCE", "years": null }``` | no |
51+
| <a name="input_versioning_lock_configuration"></a> [versioning_lock_configuration](#input_versioning_lock_configuration) | Specifies the Object Lock rule for the bucket. Requires versioning. | ```object({ mode = optional(string, "GOVERNANCE"), days = optional(number), years = optional(number), })``` | ```{ "days": null, "years": null }``` | no |
5252
| <a name="input_website_index"></a> [website_index](#input_website_index) | Website Configuration. | `string` | `null` | no |
5353

5454
## Outputs

main.tf

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,16 @@ resource "scaleway_object_bucket_lock_configuration" "this" {
5454

5555
rule {
5656
default_retention {
57-
mode = var.versioning_lock_configuration["mode"]
58-
days = var.versioning_lock_configuration["days"]
59-
years = var.versioning_lock_configuration["years"]
57+
mode = var.versioning_lock_configuration.mode
58+
days = var.versioning_lock_configuration.days
59+
years = var.versioning_lock_configuration.years
60+
}
61+
}
62+
63+
lifecycle {
64+
precondition {
65+
condition = var.versioning_enabled ? (var.versioning_lock_configuration.days != null) != (var.versioning_lock_configuration.years != null) : true
66+
error_message = "Exactly one of 'days' or 'years' must be provided when versioning is enabled."
6067
}
6168
}
6269
}

variables.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,11 @@ variable "versioning_enabled" {
7777
variable "versioning_lock_configuration" {
7878
description = "Specifies the Object Lock rule for the bucket. Requires versioning."
7979
type = object({
80-
mode = string,
80+
mode = optional(string, "GOVERNANCE"),
8181
days = optional(number),
8282
years = optional(number),
8383
})
8484
default = {
85-
mode = "GOVERNANCE"
8685
days = null,
8786
years = null,
8887
}

0 commit comments

Comments
 (0)