【问题标题】:Terraform Conditional VariablesTerraform 条件变量
【发布时间】:2018-01-15 07:55:30
【问题描述】:

我的 terraform 配置中有一个模板,我将变量的值写入其中,如下所示:

data "template_file" "config" {
  template = "${file("${path.module}/templates/${var.json_config}")}"

  vars {
    is_enabled = "${var.is_enabled}"
  }
}

现在is_enabled 是一个布尔字符串,设置为truefalse。现在基于这是对还是错,我想设置另一个变量。在伪代码中它看起来像这样:

如果 is_enabled == true 路径 = /一个/路径/ 别的 路径 = /另一个/路径

我查看了conditional values,但它似乎是为了提供资源。我将如何使用它在模板文件中设置变量?

【问题讨论】:

    标签: amazon-web-services terraform


    【解决方案1】:

    模板使用与 Terraform 中所有其他字符串相同的插值语法。 Documentation is available

    所以在你的情况下它看起来像这样:

    path = ${is_enabled ? "/one/path/" : "/another/path"}
    

    【讨论】:

    • 应该是var.is_enabled
    • @BMW 实际上没有,因为这是模板,而不是 Terraform 资源。
    猜你喜欢
    • 2020-12-14
    • 2019-04-11
    • 2021-11-20
    • 2018-11-24
    • 2021-09-18
    • 2021-12-12
    • 2020-07-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多