Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Terraform:如果子网络不存在,请将接口设置为null_Terraform_Terraform Provider Gcp - Fatal编程技术网

Terraform:如果子网络不存在,请将接口设置为null

Terraform:如果子网络不存在,请将接口设置为null,terraform,terraform-provider-gcp,Terraform,Terraform Provider Gcp,我正在创建一个自定义模块,用于在GCP中创建多nic虚拟机。在部署时,VM可能不需要使用多个接口 如果子网络不存在,是否可以将网络接口设置为空值?如果可能的话,我希望避免为每个接口计数创建多个模块 resource "google_compute_instance" "vm" { name = "${var.vm_name}" machine_type = "${var.machine_type}" zone

我正在创建一个自定义模块,用于在GCP中创建多nic虚拟机。在部署时,VM可能不需要使用多个接口

如果子网络不存在,是否可以将网络接口设置为空值?如果可能的话,我希望避免为每个接口计数创建多个模块


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"
  }
}
你能把本地人和计数结合起来吗

范例

locals {
  interface_num = "${var.is_subnetwork_3 ? 0 : 3}"
}

resource "google_whatever" "name" {
  count = "${local.interface_num}"
  // config
}
将参数设置为null在0.12中可用。