问题
I want to have a terraform blueprint that quits given a certain condition at the top.
If the var.available
is set to false, I want the blueprint to stop everything and throw an error. What is the syntax for this? I cannot find it in the doc files anywhere. Does this functionality even exist in terraform yet?
Note: this code is in a .tf blueprint file
My code:
available_ports = "${var.available ? 1 : quit_here}"
回答1:
There is a workaround to stop the Terraform script from executing based on a condition. All it needs is a null_resource:
resource "null_resource" "condition_checker" {
count = "${var.variable == 1 ? 0 : 1}"
"Insert your custom error message" = true
}
This workaround is explained by Jamie BitFlight here: Ability to raise an error #15469
There is limitation to this workaround. It does not work with -target
enabled while running Terraform.
来源:https://stackoverflow.com/questions/48388902/quit-condition-on-terraform-blueprint