Quit condition on Terraform blueprint

落花浮王杯 提交于 2021-01-27 23:33:33

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!