【发布时间】:2018-06-01 15:49:45
【问题描述】:
环境:
- terraform v0.10.7
- 谷歌云平台
- 用于创建后端、变量等的各种 .tf 文件
问题:
我能够创建多个 vm 实例以及多个附加磁盘(boot_disk 在每个实例上都可以正常工作)但我希望能够将这些附加磁盘相应地附加到每个 vm 而不必为每个 vm 单独添加(如果这是有道理的!)。
到目前为止,我的代码是(它适用于构建多个计算实例和多个额外的磁盘):注意(我已经注释掉了attached_disk which errors atm)
# vm1.tf
variable "node_count" {
default = "3"
}
resource "google_compute_disk" "test-node-1-index-disk-" {
count = "${var.node_count}"
name = "test-node-1-index-disk-${count.index}-data"
type = "pd-standard"
zone = "${var.zone}"
size = "5"
}
resource "google_compute_instance" "test-node-" {
count = "${var.node_count}"
name = "test-node-${count.index}"
machine_type = "${var.machine_type}"
zone = "${var.zone}"
boot_disk {
initialize_params {
image = "${var.image}"
}
}
# attached_disk {
# source = "${google_compute_disk.test-node-1-index-disk-0}"
# device_name = "${google_compute_disk.test-node-1-index-disk-0}"
# }
network_interface {
network = "default"
access_config {
// Ephemeral IP
}
}
}
如果我做单独的 .tf,attached_disk 工作没问题。
我想要的最终状态,is to be able to build multiple vm's, multiple additional disks using count and attach/assign each added disk to each vm instance with a relationship of 1:1 but preferable within a single .tf and block...
我想,我可以考虑应用一个 post gcloud compute 命令来附加(知道预期的命名约定),但我希望它更加动态并在创建时完成。
我是不是搞错了? 非常感谢任何帮助/指针!
谢谢 布里
【问题讨论】: