Terraform,有条件地执行模板文件中的某些代码行

问题描述 投票:0回答:1

在terraform中,有没有办法有条件地执行模板文件中的某些代码行?例如:

我有一个 test.sh.tpl 文件定义如下,从 main.tf 调用:

#!/bin/bash
echo ${test_key} > /opt/test_key.properties

在上面的“test_key”值是从变量分配的

现在我只想在 ${test_key} 值不为空时执行上面的代码。我尝试了这个,但即使值存在也不起作用

{ if ${test_key} != "" }

echo ${test_key} > /opt/test_key.properties

{ endif }
terraform terraform-provider-aws
1个回答
9
投票

可能是因为你错过了%

%{ if ${test_key} != "" }

echo ${test_key} > /opt/test_key.properties

%{ endif }

https://www.terraform.io/docs/language/expressions/strings.html

© www.soinside.com 2019 - 2024. All rights reserved.