【问题标题】:How to append to a list in Terraform?如何附加到 Terraform 中的列表?
【发布时间】:2019-09-21 06:51:03
【问题描述】:
我有一些通用形式的代码:
variable "foo" {
type = "list"
default = [ 1,2,3 ]
}
resource "bar_type" "bar" {
bar_field = "${var.foo}"
}
我想在不修改 foo 的情况下将附加值附加到 bar_field。我怎样才能做到这一点?我在他们的文档中看不到任何类型的联系或附加功能。
这是 0.11.x Terraform
【问题讨论】:
标签:
list
append
concatenation
terraform
【解决方案1】:
您可以为此使用concat 函数。扩展您问题中的示例:
variable "foo" {
type = "list"
default = [ 1,2,3 ]
}
# assume a value of 4 of type number is the additional value to be appended
resource "bar_type" "bar" {
bar_field = "${concat(var.foo, [4])}"
}
附加到分配给bar_field 的值,同时确保var.foo 保持不变。