如何在Terraform Template DSL中将字符串连接到变量



我将map从地形代码传递到jinja2,以创建一个可见的hosts文件。在hosts文件中,我使用以下代码打印映射,并且工作正常。

1. %{ for key, value in cat ~}
2. [${ key }]
3. %{ for v in value ~} 
4. ${ v }
5. %{ endfor ~}
6. %{ endfor ~}

我现在正试图用密钥附加:children,但它不起作用。我尝试了以下04种方法来改变上面代码中的第2行,但没有运气。遵循Jinja

中的链接字符串连接
Attempt 1:
[${ key|join(":children") }]
Attempt 2:
[${ key + ':children' }]
Attempt 3:
[${ key ~ ':children' }]
Attempt 4:
[${ key ~ ':children' ~}]

[${ key }:children]成功了,所以完整的答案是

%{ for key, value in cat ~}
[${ key }:children]
{ for v in value ~} 
${ v }
%{ endfor ~}
%{ endfor ~}

将得到

[blue:children]
[green:children]

最新更新