是否可以将许多ENV一起传递到Terraform中的模板文件,而不必像这样分别声明它们:
data "template_file" "test_template" {
template = file("templates/container.tpl")
vars = {
ENV1 = var.ENV1
ENV2 = var.ENV2
ENV3 = var.ENV3
ENV4 = var.ENV4
ENV5 = var.ENV5
}
}
在模板中是否像这样?
[
{
"essential": true,
"memory": 300,
"name": "client",
"cpu": 300,
"image": "some_image",
"portMappings": [
{
"containerPort": 3000,
"hostPort": 0
}
],
"environment": [
{ "name": "ENV1", "value": "${ENV1}" },
{ "name": "ENV2", "value": "${ENV2}" },
{ "name": "ENV3", "value": "${ENV3}" },
{ "name": "ENV4", "value": "${ENV4}" },
{ "name": "ENV5", "value": "${ENV5}" },
]
}
]
答案 0 :(得分:0)
在Terraform 0.12中,建议您使用:
https://www.terraform.io/docs/configuration/functions/templatefile.html
模板:
ctrl + shift + o
致电:
%{ for addr in ip_addrs ~}
backend ${addr}:${port}
%{ endfor ~}