我正在创建一个自定义模块,该模块在GCP中创建一个多NIC虚拟机。在部署时,可能会出现VM不需要使用多个接口的情况。
如果子网不存在,是否可以将network_interface设置为空值?我希望尽可能避免为每个接口计数创建多个模块。
resource "google_compute_instance" "vm" {
name = "${var.vm_name}"
machine_type = "${var.machine_type}"
zone = "${var.zone}"
min_cpu_platform = "${var.cpu_platform}"
network_interface {
subnetwork = "${google_compute_subnetwork.subnetwork1.name}"
}
network_interface {
subnetwork = "${google_compute_subnetwork.subnetwork2.name}"
}
network_interface {
// PSEUDO CODE
subnetwork = if (subnetwork3 == true) {
"${google_compute_subnetwork.subnetwork3.name}"
else
"do nothing or set null"
}
}
答案 0 :(得分:1)
您可以将locals
与count
结合吗?
示例
locals {
interface_num = "${var.is_subnetwork_3 ? 0 : 3}"
}
resource "google_whatever" "name" {
count = "${local.interface_num}"
// config
}