Skip to content

Commit

Permalink
OPS-0 Add validations for lifecycle parameter (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
snovikov authored Mar 3, 2023
1 parent 7e88234 commit feaf333
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
}

# -------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit feaf333

Please sign in to comment.