Terraform 蓝图上的退出条件 [英] Quit condition on Terraform blueprint

查看:14
本文介绍了Terraform 蓝图上的退出条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个 terraform 蓝图,在顶部给定特定条件退出.

I want to have a terraform blueprint that quits given a certain condition at the top.

如果 var.available 设置为 false,我希望蓝图停止一切并抛出错误.这个的语法是什么?我无法在任何地方的 doc 文件中找到它.terraform 中是否还存在此功能?

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?

注意:此代码位于 .tf 蓝图文件中

Note: this code is in a .tf blueprint file

我的代码:

available_ports = "${var.available ? 1 : quit_here}"

推荐答案

有一种解决方法可以根据条件停止执行 Terraform 脚本.它只需要一个 null_resource:

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
}

Jamie BitFlight 解释了此解决方法:能够引发错误 #15469

此解决方法存在局限性.它不适用于在运行 Terraform 时启用的 -target.

There is limitation to this workaround. It does not work with -target enabled while running Terraform.

这篇关于Terraform 蓝图上的退出条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆