Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/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
Google compute engine GCP计算引擎网络接口地形错误_Google Compute Engine_Terraform_Terraform Provider Gcp - Fatal编程技术网

Google compute engine GCP计算引擎网络接口地形错误

Google compute engine GCP计算引擎网络接口地形错误,google-compute-engine,terraform,terraform-provider-gcp,Google Compute Engine,Terraform,Terraform Provider Gcp,我的地形文件如下所示: resource "google_compute_instance" "virtual_instance" { name = "${var.instance_name}" machine_type = "${var.instance_type}" zone = "${var.zone}" lifecycle { ignore_changes = ["boot_disk.0.initialize_params.0.image"] } boot

我的地形文件如下所示:

resource "google_compute_instance" "virtual_instance" {
  name = "${var.instance_name}"
  machine_type = "${var.instance_type}"
  zone = "${var.zone}"
  lifecycle {
    ignore_changes = ["boot_disk.0.initialize_params.0.image"]
  }
  boot_disk {
    initialize_params {
      image = "ubuntu-os-cloud/ubuntu-1604-lts"
      size = "30"
      type = "pd-standard"
    }
  }
  network_interface {
    network = "default"
    access_config {}
  }

  attached_disk {
    source = "${google_compute_disk.managed_data_disk.name}"
    mode = "READ_WRITE"
  }
  metadata {
  }
}
上面的代码创建了该实例。但当我改变时,网络接口块如下所述

  network_interface {
    network = "${module.vpc.vpc_name}"
    subnetwork = "${module.vpc.subnet_name}"
    access_config {}
  }
专有网络模块是:

resource "google_compute_network" "vpc" {
 name                    = "${var.name}-vpc"
 auto_create_subnetworks = "false"
}

resource "google_compute_subnetwork" "subnet_public" {
    name = "${var.subnet_name_public}"
    ip_cidr_range = "${var.subnet_cidr_public}"
    network = "${var.name}-vpc"
    depends_on    = ["google_compute_network.vpc"]
    region      = "${var.region}"
}

resource "google_compute_firewall" "firewall" {
  name    = "${var.name}-firewall"
  network = "${google_compute_network.vpc.name}"

  allow {
    protocol = "icmp"
  }

  allow {
    protocol = "tcp"
    ports    = ["22"]
  }

  source_ranges = ["0.0.0.0/0"]
}
当我切换到网络接口时,自定义值。它抛出的错误是

google\u compute\u实例。虚拟\u实例:创建网络接口时出错:必须提供一个网络或子网络


感谢@ydaetskcoR,请在这方面帮助我。如果选择
网络接口的自定义值
。你不能同时提到
网络
子网络
。您将只选择下面提到的
子网络

network_interface {
    subnetwork = "${module.vpc.subnet_name}"
    access_config {}
}

这个错误解释了这一点。您只能使用
网络
子网络
两者都不能使用。是的。当我使用
网络
时。它给出了错误提示google_compute_instance.virtual_instance:创建实例时出错:googleapi:错误400:字段“resource.networkInterfaces[0]”的值无效:“”。应为自定义子网模式网络指定子网,无效。但是当我选择custom
subnetwork
时,只有它成功了。谢天谢地,Ydaetskcor遇到了类似的问题,并尝试了该解决方案,但没有解决问题,结果发现我的子网名称搞错了。