GCP compute_engine 网络接口地形错误
GCP compute_engine network interface terraform error
我的地形文件如下所示:
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_interface {
network = "${module.vpc.vpc_name}"
subnetwork = "${module.vpc.subnet_name}"
access_config {}
}
VPC 模块是:
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"]
}
当我改成network_interface自定义值的时候。它抛出的错误是
google_compute_instance.virtual_instance:创建网络接口时出错:必须提供网络或子网之一
请帮我解决这个问题
提前感谢@ydaetskcoR。如果您选择 network_interface
的自定义值。您不能同时提及 network
和 subnetwork
。您将仅选择下面提到的 subnetwork
个值。
network_interface {
subnetwork = "${module.vpc.subnet_name}"
access_config {}
}
我的地形文件如下所示:
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_interface {
network = "${module.vpc.vpc_name}"
subnetwork = "${module.vpc.subnet_name}"
access_config {}
}
VPC 模块是:
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"]
}
当我改成network_interface自定义值的时候。它抛出的错误是
google_compute_instance.virtual_instance:创建网络接口时出错:必须提供网络或子网之一
请帮我解决这个问题
提前感谢@ydaetskcoR。如果您选择 network_interface
的自定义值。您不能同时提及 network
和 subnetwork
。您将仅选择下面提到的 subnetwork
个值。
network_interface {
subnetwork = "${module.vpc.subnet_name}"
access_config {}
}