我需要迭代本地执行提供程序中的变量列表。那可能吗?
变量.tf:
variable "items" {
default = []
}
Run Code Online (Sandbox Code Playgroud)
主要.tf:
resource "null_resource" "loop_list" {
provisioner "local-exec" {
interpreter = ["/bin/bash", "-c"]
command = <<EOF
for i in ${join(' ', var.items)}
print $i
done
EOF
}
}
Run Code Online (Sandbox Code Playgroud)
您应该能够使用环境。像这样的东西:
variable "items" {
default = ["item1", "item2"]
}
resource "null_resource" "loop_list" {
provisioner "local-exec" {
command = "for item in $ITEMS; do echo $item >> test-file; done"
environment = { ITEMS = join(" ", var.items) }
}
}
Run Code Online (Sandbox Code Playgroud)
地点terraform apply和cat test-file产量:
item1
item2
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5024 次 |
| 最近记录: |