-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Closed as not planned
Labels
custom-conditionsFeedback on variable validation, preconditions. postconditions, checks, and test assertionsFeedback on variable validation, preconditions. postconditions, checks, and test assertionsduplicateissue closed because another issue already tracks this problemissue closed because another issue already tracks this problem
Description
Sometimes I have variables like shut_down_on_weekends:
variable environment_type {
type = string
description = "test or prod"
}
variable shut_down_on_weekends {
type = bool
description = "You can't shut production environments down on the weekend"
default = false
}
locals {
actually_shut_down = var.shut_down_on_weekends && var.environment_type == "test"
}Rather than creating an intermediate local to silently fix the issue, I would prefer to use variable validation to raise an error at planning time:
variable shut_down_on_weekends {
type = bool
validation {
condition = var.shut_down_on_weekends || var.environment_type == "test"
error_message = "You can only shut test environments down on the weekend."
}
}It would be possible to write cyclic dependencies with this functionality, so some care would need to be made to ensure that case is detected.
Tritium-VLK, jhoos, matteomazza91, jeffmccollum, FredrikMPS and 37 more
Metadata
Metadata
Assignees
Labels
custom-conditionsFeedback on variable validation, preconditions. postconditions, checks, and test assertionsFeedback on variable validation, preconditions. postconditions, checks, and test assertionsduplicateissue closed because another issue already tracks this problemissue closed because another issue already tracks this problem