From 4dc6a0ac172606e16d5905b766cc31c18d574f97 Mon Sep 17 00:00:00 2001 From: Nathan McKinley Date: Tue, 11 Sep 2018 13:56:58 -0700 Subject: [PATCH 1/2] Enable multiple alias IP ranges for compute instance. --- google/resource_compute_instance.go | 1 - google/resource_compute_instance_test.go | 23 +++++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/google/resource_compute_instance.go b/google/resource_compute_instance.go index 18fdc052510..643c12b9cce 100644 --- a/google/resource_compute_instance.go +++ b/google/resource_compute_instance.go @@ -218,7 +218,6 @@ func resourceComputeInstance() *schema.Resource { "alias_ip_range": &schema.Schema{ Type: schema.TypeList, - MaxItems: 1, Optional: true, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ diff --git a/google/resource_compute_instance_test.go b/google/resource_compute_instance_test.go index db349349a21..456a1a80f4b 100644 --- a/google/resource_compute_instance_test.go +++ b/google/resource_compute_instance_test.go @@ -2887,6 +2887,10 @@ resource "google_compute_subnetwork" "inst-test-subnetwork" { range_name = "inst-test-secondary" ip_cidr_range = "172.16.0.0/20" } + secondary_ip_range { + range_name = "inst-test-tertiary" + ip_cidr_range = "10.1.0.0/16" + } } resource "google_compute_instance" "foobar" { name = "%s" @@ -2902,10 +2906,17 @@ resource "google_compute_instance" "foobar" { network_interface { subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.self_link}" - alias_ip_range { - subnetwork_range_name = "${google_compute_subnetwork.inst-test-subnetwork.secondary_ip_range.0.range_name}" - ip_cidr_range = "172.16.0.0/24" - } + alias_ip_range = [ + { + subnetwork_range_name = "${google_compute_subnetwork.inst-test-subnetwork.secondary_ip_range.0.range_name}" + ip_cidr_range = "172.16.0.0/24" + }, + { + subnetwork_range_name = "${google_compute_subnetwork.inst-test-subnetwork.secondary_ip_range.1.range_name}" + ip_cidr_range = "10.1.0.0/20" + } + ] + } }`, network, subnet, instance) } @@ -2929,6 +2940,10 @@ resource "google_compute_subnetwork" "inst-test-subnetwork" { range_name = "inst-test-secondary" ip_cidr_range = "172.16.0.0/20" } + secondary_ip_range { + range_name = "inst-test-tertiary" + ip_cidr_range = "10.1.0.0/16" + } } resource "google_compute_instance" "foobar" { name = "%s" From 55bec39427ba621dc23b8be3e5c63fc1d8c7489f Mon Sep 17 00:00:00 2001 From: Nathan McKinley Date: Tue, 11 Sep 2018 16:57:43 -0700 Subject: [PATCH 2/2] Fix indentation in all instance tests. --- google/resource_compute_instance_test.go | 195 +++++++++++------------ 1 file changed, 97 insertions(+), 98 deletions(-) diff --git a/google/resource_compute_instance_test.go b/google/resource_compute_instance_test.go index 456a1a80f4b..05c99ff407b 100644 --- a/google/resource_compute_instance_test.go +++ b/google/resource_compute_instance_test.go @@ -1576,7 +1576,7 @@ resource "google_compute_instance" "foobar" { labels { my_key = "my_value" my_other_key = "my_other_value" - } + } } `, instance) } @@ -2788,83 +2788,83 @@ data "google_compute_image" "my_image" { } resource "google_compute_instance" "foobar" { - name = "%s" - machine_type = "n1-standard-1" - zone = "us-east1-d" - - boot_disk { - initialize_params { - image = "${data.google_compute_image.my_image.self_link}" - } - } - - network_interface { - network = "default" - } - - scheduling { - # Instances with guest accelerators do not support live migration. - on_host_maintenance = "TERMINATE" - } - - guest_accelerator { - count = %d - type = "nvidia-tesla-k80" - } + name = "%s" + machine_type = "n1-standard-1" + zone = "us-east1-d" + + boot_disk { + initialize_params { + image = "${data.google_compute_image.my_image.self_link}" + } + } + + network_interface { + network = "default" + } + + scheduling { + # Instances with guest accelerators do not support live migration. + on_host_maintenance = "TERMINATE" + } + + guest_accelerator { + count = %d + type = "nvidia-tesla-k80" + } }`, instance, count) } func testAccComputeInstance_minCpuPlatform(instance string) string { return fmt.Sprintf(` data "google_compute_image" "my_image" { - family = "debian-9" - project = "debian-cloud" + family = "debian-9" + project = "debian-cloud" } resource "google_compute_instance" "foobar" { - name = "%s" - machine_type = "n1-standard-1" - zone = "us-east1-d" + name = "%s" + machine_type = "n1-standard-1" + zone = "us-east1-d" - boot_disk { - initialize_params { - image = "${data.google_compute_image.my_image.self_link}" - } - } + boot_disk { + initialize_params { + image = "${data.google_compute_image.my_image.self_link}" + } + } - network_interface { - network = "default" - } + network_interface { + network = "default" + } - min_cpu_platform = "Intel Haswell" + min_cpu_platform = "Intel Haswell" }`, instance) } func testAccComputeInstance_primaryAliasIpRange(instance string) string { return fmt.Sprintf(` data "google_compute_image" "my_image" { - family = "debian-9" - project = "debian-cloud" + family = "debian-9" + project = "debian-cloud" } resource "google_compute_instance" "foobar" { - name = "%s" - machine_type = "n1-standard-1" - zone = "us-east1-d" - - boot_disk { - initialize_params { - image = "${data.google_compute_image.my_image.self_link}" - } - } - - network_interface { - network = "default" - - alias_ip_range { - ip_cidr_range = "/24" - } - } + name = "%s" + machine_type = "n1-standard-1" + zone = "us-east1-d" + + boot_disk { + initialize_params { + image = "${data.google_compute_image.my_image.self_link}" + } + } + + network_interface { + network = "default" + + alias_ip_range { + ip_cidr_range = "/24" + } + } }`, instance) } @@ -2893,31 +2893,31 @@ resource "google_compute_subnetwork" "inst-test-subnetwork" { } } resource "google_compute_instance" "foobar" { - name = "%s" - machine_type = "n1-standard-1" - zone = "us-east1-d" - - boot_disk { - initialize_params { - image = "${data.google_compute_image.my_image.self_link}" - } - } - - network_interface { - subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.self_link}" - - alias_ip_range = [ - { - subnetwork_range_name = "${google_compute_subnetwork.inst-test-subnetwork.secondary_ip_range.0.range_name}" - ip_cidr_range = "172.16.0.0/24" - }, - { - subnetwork_range_name = "${google_compute_subnetwork.inst-test-subnetwork.secondary_ip_range.1.range_name}" - ip_cidr_range = "10.1.0.0/20" - } - ] + name = "%s" + machine_type = "n1-standard-1" + zone = "us-east1-d" + + boot_disk { + initialize_params { + image = "${data.google_compute_image.my_image.self_link}" + } + } + + network_interface { + subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.self_link}" + + alias_ip_range = [ + { + subnetwork_range_name = "${google_compute_subnetwork.inst-test-subnetwork.secondary_ip_range.0.range_name}" + ip_cidr_range = "172.16.0.0/24" + }, + { + subnetwork_range_name = "${google_compute_subnetwork.inst-test-subnetwork.secondary_ip_range.1.range_name}" + ip_cidr_range = "10.1.0.0/20" + } + ] - } + } }`, network, subnet, instance) } @@ -2946,23 +2946,22 @@ resource "google_compute_subnetwork" "inst-test-subnetwork" { } } resource "google_compute_instance" "foobar" { - name = "%s" - machine_type = "n1-standard-1" - zone = "us-east1-d" - - boot_disk { - initialize_params { - image = "${data.google_compute_image.my_image.self_link}" - } - } - - network_interface { - subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.self_link}" - - alias_ip_range { - ip_cidr_range = "10.0.1.0/24" - } - } + name = "%s" + machine_type = "n1-standard-1" + zone = "us-east1-d" + + boot_disk { + initialize_params { + image = "${data.google_compute_image.my_image.self_link}" + } + } + + network_interface { + subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.self_link}" + alias_ip_range { + ip_cidr_range = "10.0.1.0/24" + } + } }`, network, subnet, instance) }