【问题标题】:Extend / Append to Terraform template_file扩展/附加到 Terraform 模板文件
【发布时间】:2019-06-04 14:39:20
【问题描述】:
使用 terraform,我想看看是否有一种方法——使用模板渲染系统——在 terraform 模块(基本模板)中定义 template_file,然后“扩展”或“附加”到渲染中实例化而不是替换。
我目前可以在任一位置定义template_file,但想知道我是否可以在每个实例的基础上构建模块模板。具体用例是 AWS EC2 上的用户数据,不同实例类型略有不同。
谢谢你,
神经元
【问题讨论】:
标签:
terraform
terraform-provider-aws
terraform-template-file
【解决方案1】:
这就是我最终发现的。
在模块中。为基本模板定义一个template_file。然后定义一个output(例如名为"module_template"),其值等于template_file 的呈现版本。
然后在实例化中,定义另一个template_file,其var 等于mod_temp = "${module.module_name.module_template}",然后在template_file 中,在必要时使用${mod_temp} 引用该变量。
我正在考虑尝试转义“超级模板”中的值,以便它们可能会在“子模板”渲染期间被插值。初步测试没有成功。