I'd like to enforce that a value is set rather than using the default "" if one of the other values is a certain string.
For example I have:
module "test_beanstalk" {
tier = "Worker"
queue = "myQueue"
///
}
in this, when tier
is set to worker
I'd like to enforce that queue
is also set. In the above example there's a scenario where the queue can be omitted resulting in aws spawning a generic one rather than using the queue that is required for that particular application.
CodePudding user response:
Such feature is not directly supported in TF. But you can force TF to error out using locals
and some condition that will simply lead to error if your verification fails. For example, in your test_beanstalk
you can have:
variable "tier" {
default = "Worker"
}
variable "queue" {
default = ""
}
locals {
if_queue_given = var.tier == "Worker" && var.queue == "" ? tonumber("queue can't be empty") : 1
}
The tonumber("queue can't be empty")
will be executed and will lead to TF error, if the condition is var.tier == "Worker" && var.queue == ""
true
.