Using validation{} block and alltrue() function :
variable "s3_shares" {
type = map(object({
s3_bucket_arn = string
client_list = list(string)
read_only = bool
default_storage_class = string
}))
default = {
"one" = {
s3_bucket_arn = "foo"
client_list = ["foo","bar"]
read_only = false
default_storage_class = "bar" # IS OK
}
"two" = {
s3_bucket_arn = "foo"
client_list = ["foo","bar"]
read_only = false
default_storage_class = "" # IS OK
}}
"three" = {
s3_bucket_arn = "foo"
client_list = ["foo","bar"]
read_only = true
default_storage_class = "" # IS OK
}}
"four" = {
s3_bucket_arn = "foo"
client_list = ["foo","bar"]
read_only = true
default_storage_class = "bar" # IS KO
}}
validation {
condition = alltrue([
for o in var.s3_shares : !(o.read_only && length(o.default_storage_class) > 0)])
error_message = "Read_only and default_storage_class are exclusive."
}
}
Mind the use case "two" where read_only is set to false and default_storage_class is empty : this will return true. This might not be the behavior you are looking for.