From feaf333315c2183685ba68a8fd6e333059da2437 Mon Sep 17 00:00:00 2001 From: Novikov Sergey Date: Fri, 3 Mar 2023 13:22:58 +0100 Subject: [PATCH] OPS-0 Add validations for lifecycle parameter (#80) --- variables.tf | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/variables.tf b/variables.tf index c79a07a..930a7e3 100644 --- a/variables.tf +++ b/variables.tf @@ -1152,6 +1152,29 @@ variable "s3_lifecycle_rules" { storage_class = string })), []) })) + + validation { + condition = length(var.s3_lifecycle_rules) > 0 ? alltrue([ + for k, v in var.s3_lifecycle_rules : (length(v["expiration"]) <= 1) + ]) : true + error_message = "Only one `expiration` block is allowed." + } + + validation { + condition = length(var.s3_lifecycle_rules) > 0 ? alltrue(flatten([ + for k, v in var.s3_lifecycle_rules : [ + for bk, bv in v["expiration"] : (bv["days"] == null || bv["date"] == null) + ]])) : true + error_message = "Either `days` or `date` value should be set for `expiration`, but not both." + } + + validation { + condition = length(var.s3_lifecycle_rules) > 0 ? alltrue(flatten([ + for k, v in var.s3_lifecycle_rules : [ + for bk, bv in v["transition"] : (bv["days"] == null || bv["date"] == null) + ]])) : true + error_message = "Either `days` or `date` value should be set for `transition`, but not both." + } } # -------------------------------------------------------------------------------------------------