在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 }
可能是因为你错过了%
%{ if ${test_key} != "" }
echo ${test_key} > /opt/test_key.properties
%{ endif }
https://www.terraform.io/docs/language/expressions/strings.html