From e98880dfdc39d5353ebed1ccaa6979929fd129af Mon Sep 17 00:00:00 2001 From: Shuya Ma <87669292+shuyama1@users.noreply.github.com> Date: Thu, 26 Oct 2023 13:00:29 -0700 Subject: [PATCH] Update node pool tests to use bootstrapped network (#9348) --- ...ta_source_google_container_cluster_test.go | 24 +- .../resource_container_node_pool_test.go.erb | 696 +++++++++++------- 2 files changed, 465 insertions(+), 255 deletions(-) diff --git a/mmv1/third_party/terraform/services/container/data_source_google_container_cluster_test.go b/mmv1/third_party/terraform/services/container/data_source_google_container_cluster_test.go index 81fa64c14c9f..5389d6f15bb0 100644 --- a/mmv1/third_party/terraform/services/container/data_source_google_container_cluster_test.go +++ b/mmv1/third_party/terraform/services/container/data_source_google_container_cluster_test.go @@ -11,12 +11,15 @@ import ( func TestAccContainerClusterDatasource_zonal(t *testing.T) { t.Parallel() + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) + acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), Steps: []resource.TestStep{ { - Config: testAccContainerClusterDatasource_zonal(acctest.RandString(t, 10)), + Config: testAccContainerClusterDatasource_zonal(acctest.RandString(t, 10), networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( acctest.CheckDataSourceStateMatchesResourceStateWithIgnores( "data.google_container_cluster.kubes", @@ -38,12 +41,15 @@ func TestAccContainerClusterDatasource_zonal(t *testing.T) { func TestAccContainerClusterDatasource_regional(t *testing.T) { t.Parallel() + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) + acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), Steps: []resource.TestStep{ { - Config: testAccContainerClusterDatasource_regional(acctest.RandString(t, 10)), + Config: testAccContainerClusterDatasource_regional(acctest.RandString(t, 10), networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( acctest.CheckDataSourceStateMatchesResourceStateWithIgnores( "data.google_container_cluster.kubes", @@ -62,34 +68,40 @@ func TestAccContainerClusterDatasource_regional(t *testing.T) { }) } -func testAccContainerClusterDatasource_zonal(suffix string) string { +func testAccContainerClusterDatasource_zonal(suffix, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "kubes" { name = "tf-test-cluster-%s" location = "us-central1-a" initial_node_count = 1 deletion_protection = false + network = "%s" + subnetwork = "%s" + } data "google_container_cluster" "kubes" { name = google_container_cluster.kubes.name location = google_container_cluster.kubes.location } -`, suffix) +`, suffix, networkName, subnetworkName) } -func testAccContainerClusterDatasource_regional(suffix string) string { +func testAccContainerClusterDatasource_regional(suffix, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "kubes" { name = "tf-test-cluster-%s" location = "us-central1" initial_node_count = 1 deletion_protection = false + network = "%s" + subnetwork = "%s" + } data "google_container_cluster" "kubes" { name = google_container_cluster.kubes.name location = google_container_cluster.kubes.location } -`, suffix) +`, suffix, networkName, subnetworkName) } diff --git a/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb b/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb index bf3663095dc6..aac2bfc21ce3 100644 --- a/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb +++ b/mmv1/third_party/terraform/services/container/resource_container_node_pool_test.go.erb @@ -17,6 +17,8 @@ func TestAccContainerNodePool_basic(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -24,7 +26,7 @@ func TestAccContainerNodePool_basic(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccContainerNodePool_basic(cluster, np), + Config: testAccContainerNodePool_basic(cluster, np, networkName, subnetworkName), }, resource.TestStep{ ResourceName: "google_container_node_pool.np", @@ -40,6 +42,8 @@ func TestAccContainerNodePool_basicWithClusterId(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -47,7 +51,7 @@ func TestAccContainerNodePool_basicWithClusterId(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_basicWithClusterId(cluster, np), + Config: testAccContainerNodePool_basicWithClusterId(cluster, np, networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.np", @@ -113,6 +117,8 @@ func TestAccContainerNodePool_namePrefix(t *testing.T) { t.Parallel() cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -120,7 +126,7 @@ func TestAccContainerNodePool_namePrefix(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccContainerNodePool_namePrefix(cluster, "tf-np-"), + Config: testAccContainerNodePool_namePrefix(cluster, "tf-np-", networkName, subnetworkName), }, resource.TestStep{ ResourceName: "google_container_node_pool.np", @@ -138,6 +144,8 @@ func TestAccContainerNodePool_noName(t *testing.T) { t.Parallel() cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -145,7 +153,7 @@ func TestAccContainerNodePool_noName(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccContainerNodePool_noName(cluster), + Config: testAccContainerNodePool_noName(cluster, networkName, subnetworkName), }, resource.TestStep{ ResourceName: "google_container_node_pool.np", @@ -161,6 +169,8 @@ func TestAccContainerNodePool_withLoggingVariantUpdates(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) nodePool := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -168,7 +178,7 @@ func TestAccContainerNodePool_withLoggingVariantUpdates(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_withLoggingVariant(cluster, nodePool, "DEFAULT"), + Config: testAccContainerNodePool_withLoggingVariant(cluster, nodePool, "DEFAULT", networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.with_logging_variant", @@ -176,7 +186,7 @@ func TestAccContainerNodePool_withLoggingVariantUpdates(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccContainerNodePool_withLoggingVariant(cluster, nodePool, "MAX_THROUGHPUT"), + Config: testAccContainerNodePool_withLoggingVariant(cluster, nodePool, "MAX_THROUGHPUT", networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.with_logging_variant", @@ -184,7 +194,7 @@ func TestAccContainerNodePool_withLoggingVariantUpdates(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccContainerNodePool_withLoggingVariant(cluster, nodePool, "DEFAULT"), + Config: testAccContainerNodePool_withLoggingVariant(cluster, nodePool, "DEFAULT", networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.with_logging_variant", @@ -200,6 +210,8 @@ func TestAccContainerNodePool_withNodeConfig(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) nodePool := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -207,7 +219,7 @@ func TestAccContainerNodePool_withNodeConfig(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccContainerNodePool_withNodeConfig(cluster, nodePool), + Config: testAccContainerNodePool_withNodeConfig(cluster, nodePool, networkName, subnetworkName), }, resource.TestStep{ ResourceName: "google_container_node_pool.np_with_node_config", @@ -218,7 +230,7 @@ func TestAccContainerNodePool_withNodeConfig(t *testing.T) { ImportStateVerifyIgnore: []string{"autoscaling.#", "node_config.0.taint"}, }, resource.TestStep{ - Config: testAccContainerNodePool_withNodeConfigUpdate(cluster, nodePool), + Config: testAccContainerNodePool_withNodeConfigUpdate(cluster, nodePool, networkName, subnetworkName), }, resource.TestStep{ ResourceName: "google_container_node_pool.np_with_node_config", @@ -237,6 +249,8 @@ func TestAccContainerNodePool_withTaintsUpdate(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) nodePool := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -244,7 +258,7 @@ func TestAccContainerNodePool_withTaintsUpdate(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccContainerNodePool_basic(cluster, nodePool), + Config: testAccContainerNodePool_basic(cluster, nodePool, networkName, subnetworkName), }, resource.TestStep{ ResourceName: "google_container_node_pool.np", @@ -252,7 +266,7 @@ func TestAccContainerNodePool_withTaintsUpdate(t *testing.T) { ImportStateVerify: true, }, resource.TestStep{ - Config: testAccContainerNodePool_withTaintsUpdate(cluster, nodePool), + Config: testAccContainerNodePool_withTaintsUpdate(cluster, nodePool, networkName, subnetworkName), }, resource.TestStep{ ResourceName: "google_container_node_pool.np", @@ -271,6 +285,8 @@ func TestAccContainerNodePool_withReservationAffinity(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-np-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -278,7 +294,7 @@ func TestAccContainerNodePool_withReservationAffinity(t *testing.T) { CheckDestroy: testAccCheckContainerClusterDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_withReservationAffinity(cluster, np), + Config: testAccContainerNodePool_withReservationAffinity(cluster, np, networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("google_container_node_pool.with_reservation_affinity", "node_config.0.reservation_affinity.#", "1"), @@ -301,6 +317,8 @@ func TestAccContainerNodePool_withReservationAffinitySpecific(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) reservation := fmt.Sprintf("tf-test-reservation-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-np-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -308,7 +326,7 @@ func TestAccContainerNodePool_withReservationAffinitySpecific(t *testing.T) { CheckDestroy: testAccCheckContainerClusterDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_withReservationAffinitySpecific(cluster, reservation, np), + Config: testAccContainerNodePool_withReservationAffinitySpecific(cluster, reservation, np, networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("google_container_node_pool.with_reservation_affinity", "node_config.0.reservation_affinity.#", "1"), @@ -337,6 +355,8 @@ func TestAccContainerNodePool_withWorkloadIdentityConfig(t *testing.T) { pid := envvar.GetTestProjectFromEnv() cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-np-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -344,7 +364,7 @@ func TestAccContainerNodePool_withWorkloadIdentityConfig(t *testing.T) { CheckDestroy: testAccCheckContainerClusterDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_withWorkloadMetadataConfig(cluster, np), + Config: testAccContainerNodePool_withWorkloadMetadataConfig(cluster, np, networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("google_container_node_pool.with_workload_metadata_config", "node_config.0.workload_metadata_config.0.mode", "GCE_METADATA"), @@ -356,7 +376,7 @@ func TestAccContainerNodePool_withWorkloadIdentityConfig(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccContainerNodePool_withWorkloadMetadataConfig_gkeMetadata(pid, cluster, np), + Config: testAccContainerNodePool_withWorkloadMetadataConfig_gkeMetadata(pid, cluster, np, networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("google_container_node_pool.with_workload_metadata_config", "node_config.0.workload_metadata_config.0.mode", "GKE_METADATA"), @@ -377,6 +397,8 @@ func TestAccContainerNodePool_withSandboxConfig(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-np-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -384,7 +406,7 @@ func TestAccContainerNodePool_withSandboxConfig(t *testing.T) { CheckDestroy: testAccCheckContainerClusterDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_withSandboxConfig(cluster, np), + Config: testAccContainerNodePool_withSandboxConfig(cluster, np, networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("google_container_node_pool.with_sandbox_config", "node_config.0.sandbox_config.0.sandbox_type", "gvisor"), @@ -406,6 +428,8 @@ func TestAccContainerNodePool_withKubeletConfig(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-np-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -413,7 +437,7 @@ func TestAccContainerNodePool_withKubeletConfig(t *testing.T) { CheckDestroy: testAccCheckContainerClusterDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "static", "100us", true, 2048), + Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "static", "100us", networkName, subnetworkName, true, 2048), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config", "node_config.0.kubelet_config.0.cpu_cfs_quota", "true"), @@ -427,7 +451,7 @@ func TestAccContainerNodePool_withKubeletConfig(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "", "", false, 1024), + Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "", "", networkName, subnetworkName, false, 1024), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config", "node_config.0.kubelet_config.0.cpu_cfs_quota", "false"), @@ -449,6 +473,8 @@ func TestAccContainerNodePool_withInvalidKubeletCpuManagerPolicy(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-np-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -456,7 +482,7 @@ func TestAccContainerNodePool_withInvalidKubeletCpuManagerPolicy(t *testing.T) { CheckDestroy: testAccCheckContainerClusterDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "dontexist", "100us", true, 1024), + Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "dontexist", "100us", networkName, subnetworkName, true, 1024), ExpectError: regexp.MustCompile(`.*to be one of \[static none \].*`), }, }, @@ -468,6 +494,8 @@ func TestAccContainerNodePool_withLinuxNodeConfig(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-np-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -476,7 +504,7 @@ func TestAccContainerNodePool_withLinuxNodeConfig(t *testing.T) { Steps: []resource.TestStep{ // Create a node pool with empty `linux_node_config.sysctls`. { - Config: testAccContainerNodePool_withLinuxNodeConfig(cluster, np, ""), + Config: testAccContainerNodePool_withLinuxNodeConfig(cluster, np, "", networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.with_linux_node_config", @@ -484,7 +512,7 @@ func TestAccContainerNodePool_withLinuxNodeConfig(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccContainerNodePool_withLinuxNodeConfig(cluster, np, "1000 20000 100000"), + Config: testAccContainerNodePool_withLinuxNodeConfig(cluster, np, "1000 20000 100000", networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.with_linux_node_config", @@ -493,7 +521,7 @@ func TestAccContainerNodePool_withLinuxNodeConfig(t *testing.T) { }, // Perform an update. { - Config: testAccContainerNodePool_withLinuxNodeConfig(cluster, np, "1000 20000 200000"), + Config: testAccContainerNodePool_withLinuxNodeConfig(cluster, np, "1000 20000 200000", networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.with_linux_node_config", @@ -509,6 +537,8 @@ func TestAccContainerNodePool_withCgroupMode(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-np-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -516,7 +546,7 @@ func TestAccContainerNodePool_withCgroupMode(t *testing.T) { CheckDestroy: testAccCheckContainerClusterDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_withCgroupMode(cluster, np, "CGROUP_MODE_V2"), + Config: testAccContainerNodePool_withCgroupMode(cluster, np, "CGROUP_MODE_V2", networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.np", @@ -525,7 +555,7 @@ func TestAccContainerNodePool_withCgroupMode(t *testing.T) { }, // Perform an update. { - Config: testAccContainerNodePool_withCgroupMode(cluster, np, "CGROUP_MODE_UNSPECIFIED"), + Config: testAccContainerNodePool_withCgroupMode(cluster, np, "CGROUP_MODE_UNSPECIFIED", networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.np", @@ -701,6 +731,8 @@ func TestAccContainerNodePool_withBootDiskKmsKey(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-np-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) if acctest.BootstrapPSARole(t, "service-", "compute-system", "roles/cloudkms.cryptoKeyEncrypterDecrypter") { t.Fatal("Stopping the test because a role was added to the policy.") @@ -712,7 +744,7 @@ func TestAccContainerNodePool_withBootDiskKmsKey(t *testing.T) { CheckDestroy: testAccCheckContainerClusterDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_withBootDiskKmsKey(cluster, np), + Config: testAccContainerNodePool_withBootDiskKmsKey(cluster, np, networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.with_boot_disk_kms_key", @@ -730,6 +762,8 @@ func TestAccContainerNodePool_withUpgradeSettings(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-np-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -737,7 +771,7 @@ func TestAccContainerNodePool_withUpgradeSettings(t *testing.T) { CheckDestroy: testAccCheckContainerClusterDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_withUpgradeSettings(cluster, np, 2, 3, "SURGE", "", 0, 0.0, ""), + Config: testAccContainerNodePool_withUpgradeSettings(cluster, np, networkName, subnetworkName, 2, 3, "SURGE", "", 0, 0.0, ""), }, { ResourceName: "google_container_node_pool.with_upgrade_settings", @@ -745,7 +779,7 @@ func TestAccContainerNodePool_withUpgradeSettings(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccContainerNodePool_withUpgradeSettings(cluster, np, 2, 1, "SURGE", "", 0, 0.0, ""), + Config: testAccContainerNodePool_withUpgradeSettings(cluster, np, networkName, subnetworkName, 2, 1, "SURGE", "", 0, 0.0, ""), }, { ResourceName: "google_container_node_pool.with_upgrade_settings", @@ -753,7 +787,7 @@ func TestAccContainerNodePool_withUpgradeSettings(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccContainerNodePool_withUpgradeSettings(cluster, np, 1, 1, "SURGE", "", 0, 0.0, ""), + Config: testAccContainerNodePool_withUpgradeSettings(cluster, np, networkName, subnetworkName, 1, 1, "SURGE", "", 0, 0.0, ""), }, { ResourceName: "google_container_node_pool.with_upgrade_settings", @@ -761,7 +795,7 @@ func TestAccContainerNodePool_withUpgradeSettings(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccContainerNodePool_withUpgradeSettings(cluster, np, 0, 0, "BLUE_GREEN", "100s", 1, 0.0, "0s"), + Config: testAccContainerNodePool_withUpgradeSettings(cluster, np, networkName, subnetworkName, 0, 0, "BLUE_GREEN", "100s", 1, 0.0, "0s"), }, { ResourceName: "google_container_node_pool.with_upgrade_settings", @@ -769,7 +803,7 @@ func TestAccContainerNodePool_withUpgradeSettings(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccContainerNodePool_withUpgradeSettings(cluster, np, 0, 0, "BLUE_GREEN", "100s", 0, 0.5, "1s"), + Config: testAccContainerNodePool_withUpgradeSettings(cluster, np, networkName, subnetworkName, 0, 0, "BLUE_GREEN", "100s", 0, 0.5, "1s"), }, { ResourceName: "google_container_node_pool.with_upgrade_settings", @@ -785,6 +819,8 @@ func TestAccContainerNodePool_withGPU(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-np-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -792,7 +828,7 @@ func TestAccContainerNodePool_withGPU(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccContainerNodePool_withGPU(cluster, np), + Config: testAccContainerNodePool_withGPU(cluster, np, networkName, subnetworkName), }, resource.TestStep{ ResourceName: "google_container_node_pool.np_with_gpu", @@ -808,6 +844,9 @@ func TestAccContainerNodePool_withManagement(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) nodePool := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) + management := ` management { auto_repair = "false" @@ -820,7 +859,7 @@ func TestAccContainerNodePool_withManagement(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccContainerNodePool_withManagement(cluster, nodePool, ""), + Config: testAccContainerNodePool_withManagement(cluster, nodePool, "", networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "google_container_node_pool.np_with_management", "management.#", "1"), @@ -836,7 +875,7 @@ func TestAccContainerNodePool_withManagement(t *testing.T) { ImportStateVerify: true, }, resource.TestStep{ - Config: testAccContainerNodePool_withManagement(cluster, nodePool, management), + Config: testAccContainerNodePool_withManagement(cluster, nodePool, management, networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr( "google_container_node_pool.np_with_management", "management.#", "1"), @@ -860,6 +899,8 @@ func TestAccContainerNodePool_withNodeConfigScopeAlias(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-np-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -867,7 +908,7 @@ func TestAccContainerNodePool_withNodeConfigScopeAlias(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccContainerNodePool_withNodeConfigScopeAlias(cluster, np), + Config: testAccContainerNodePool_withNodeConfigScopeAlias(cluster, np, networkName, subnetworkName), }, resource.TestStep{ ResourceName: "google_container_node_pool.np_with_node_config_scope_alias", @@ -884,6 +925,8 @@ func TestAccContainerNodePool_regionalAutoscaling(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -891,7 +934,7 @@ func TestAccContainerNodePool_regionalAutoscaling(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccContainerNodePool_regionalAutoscaling(cluster, np), + Config: testAccContainerNodePool_regionalAutoscaling(cluster, np, networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("google_container_node_pool.np", "autoscaling.0.min_node_count", "1"), resource.TestCheckResourceAttr("google_container_node_pool.np", "autoscaling.0.max_node_count", "3"), @@ -903,7 +946,7 @@ func TestAccContainerNodePool_regionalAutoscaling(t *testing.T) { ImportStateVerify: true, }, resource.TestStep{ - Config: testAccContainerNodePool_updateAutoscaling(cluster, np), + Config: testAccContainerNodePool_updateAutoscaling(cluster, np, networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("google_container_node_pool.np", "autoscaling.0.min_node_count", "0"), resource.TestCheckResourceAttr("google_container_node_pool.np", "autoscaling.0.max_node_count", "5"), @@ -915,7 +958,7 @@ func TestAccContainerNodePool_regionalAutoscaling(t *testing.T) { ImportStateVerify: true, }, resource.TestStep{ - Config: testAccContainerNodePool_basic(cluster, np), + Config: testAccContainerNodePool_basic(cluster, np, networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( resource.TestCheckNoResourceAttr("google_container_node_pool.np", "autoscaling.0.min_node_count"), resource.TestCheckNoResourceAttr("google_container_node_pool.np", "autoscaling.0.max_node_count"), @@ -939,6 +982,8 @@ func TestAccContainerNodePool_totalSize(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -946,7 +991,7 @@ func TestAccContainerNodePool_totalSize(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccContainerNodePool_totalSize(cluster, np), + Config: testAccContainerNodePool_totalSize(cluster, np, networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("google_container_node_pool.np", "autoscaling.0.total_min_node_count", "4"), resource.TestCheckResourceAttr("google_container_node_pool.np", "autoscaling.0.total_max_node_count", "12"), @@ -959,7 +1004,7 @@ func TestAccContainerNodePool_totalSize(t *testing.T) { ImportStateVerify: true, }, resource.TestStep{ - Config: testAccContainerNodePool_updateTotalSize(cluster, np), + Config: testAccContainerNodePool_updateTotalSize(cluster, np, networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("google_container_node_pool.np", "autoscaling.0.total_min_node_count", "2"), resource.TestCheckResourceAttr("google_container_node_pool.np", "autoscaling.0.total_max_node_count", "22"), @@ -972,7 +1017,7 @@ func TestAccContainerNodePool_totalSize(t *testing.T) { ImportStateVerify: true, }, resource.TestStep{ - Config: testAccContainerNodePool_basicTotalSize(cluster, np), + Config: testAccContainerNodePool_basicTotalSize(cluster, np, networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( resource.TestCheckNoResourceAttr("google_container_node_pool.np", "autoscaling.0.min_node_count"), resource.TestCheckNoResourceAttr("google_container_node_pool.np", "autoscaling.0.max_node_count"), @@ -995,6 +1040,8 @@ func TestAccContainerNodePool_autoscaling(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1002,7 +1049,7 @@ func TestAccContainerNodePool_autoscaling(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccContainerNodePool_autoscaling(cluster, np), + Config: testAccContainerNodePool_autoscaling(cluster, np, networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("google_container_node_pool.np", "autoscaling.0.min_node_count", "1"), resource.TestCheckResourceAttr("google_container_node_pool.np", "autoscaling.0.max_node_count", "3"), @@ -1014,7 +1061,7 @@ func TestAccContainerNodePool_autoscaling(t *testing.T) { ImportStateVerify: true, }, resource.TestStep{ - Config: testAccContainerNodePool_updateAutoscaling(cluster, np), + Config: testAccContainerNodePool_updateAutoscaling(cluster, np, networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("google_container_node_pool.np", "autoscaling.0.min_node_count", "0"), resource.TestCheckResourceAttr("google_container_node_pool.np", "autoscaling.0.max_node_count", "5"), @@ -1026,7 +1073,7 @@ func TestAccContainerNodePool_autoscaling(t *testing.T) { ImportStateVerify: true, }, resource.TestStep{ - Config: testAccContainerNodePool_basic(cluster, np), + Config: testAccContainerNodePool_basic(cluster, np, networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( resource.TestCheckNoResourceAttr("google_container_node_pool.np", "autoscaling.0.min_node_count"), resource.TestCheckNoResourceAttr("google_container_node_pool.np", "autoscaling.0.max_node_count"), @@ -1049,6 +1096,8 @@ func TestAccContainerNodePool_resize(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1056,7 +1105,7 @@ func TestAccContainerNodePool_resize(t *testing.T) { CheckDestroy: testAccCheckContainerClusterDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_additionalZones(cluster, np), + Config: testAccContainerNodePool_additionalZones(cluster, np, networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("google_container_node_pool.np", "node_count", "2"), ), @@ -1067,7 +1116,7 @@ func TestAccContainerNodePool_resize(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccContainerNodePool_resize(cluster, np), + Config: testAccContainerNodePool_resize(cluster, np, networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("google_container_node_pool.np", "node_count", "3"), ), @@ -1086,6 +1135,8 @@ func TestAccContainerNodePool_version(t *testing.T) { t.Parallel() cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1093,7 +1144,7 @@ func TestAccContainerNodePool_version(t *testing.T) { CheckDestroy: testAccCheckContainerClusterDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_version(cluster, np), + Config: testAccContainerNodePool_version(cluster, np, networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.np", @@ -1101,7 +1152,7 @@ func TestAccContainerNodePool_version(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccContainerNodePool_updateVersion(cluster, np), + Config: testAccContainerNodePool_updateVersion(cluster, np, networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.np", @@ -1109,7 +1160,7 @@ func TestAccContainerNodePool_version(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccContainerNodePool_version(cluster, np), + Config: testAccContainerNodePool_version(cluster, np, networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.np", @@ -1125,6 +1176,8 @@ func TestAccContainerNodePool_regionalClusters(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1132,7 +1185,7 @@ func TestAccContainerNodePool_regionalClusters(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccContainerNodePool_regionalClusters(cluster, np), + Config: testAccContainerNodePool_regionalClusters(cluster, np, networkName, subnetworkName), }, resource.TestStep{ ResourceName: "google_container_node_pool.np", @@ -1148,6 +1201,8 @@ func TestAccContainerNodePool_012_ConfigModeAttr(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1155,7 +1210,7 @@ func TestAccContainerNodePool_012_ConfigModeAttr(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_012_ConfigModeAttr1(cluster, np), + Config: testAccContainerNodePool_012_ConfigModeAttr1(cluster, np, networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.np", @@ -1163,7 +1218,7 @@ func TestAccContainerNodePool_012_ConfigModeAttr(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccContainerNodePool_012_ConfigModeAttr2(cluster, np), + Config: testAccContainerNodePool_012_ConfigModeAttr2(cluster, np, networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.np", @@ -1179,6 +1234,8 @@ func TestAccContainerNodePool_EmptyGuestAccelerator(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1187,7 +1244,7 @@ func TestAccContainerNodePool_EmptyGuestAccelerator(t *testing.T) { Steps: []resource.TestStep{ { // Test alternative way to specify an empty node pool - Config: testAccContainerNodePool_EmptyGuestAccelerator(cluster, np), + Config: testAccContainerNodePool_EmptyGuestAccelerator(cluster, np, networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.np", @@ -1196,7 +1253,7 @@ func TestAccContainerNodePool_EmptyGuestAccelerator(t *testing.T) { }, { // Test alternative way to specify an empty node pool - Config: testAccContainerNodePool_PartialEmptyGuestAccelerator(cluster, np, 1), + Config: testAccContainerNodePool_PartialEmptyGuestAccelerator(cluster, np, networkName, subnetworkName, 1), }, { ResourceName: "google_container_node_pool.np", @@ -1205,13 +1262,13 @@ func TestAccContainerNodePool_EmptyGuestAccelerator(t *testing.T) { }, { // Assert that changes in count from 1 result in a diff - Config: testAccContainerNodePool_PartialEmptyGuestAccelerator(cluster, np, 2), + Config: testAccContainerNodePool_PartialEmptyGuestAccelerator(cluster, np, networkName, subnetworkName, 2), ExpectNonEmptyPlan: true, PlanOnly: true, }, { // Assert that adding another accelerator block will also result in a diff - Config: testAccContainerNodePool_PartialEmptyGuestAccelerator2(cluster, np), + Config: testAccContainerNodePool_PartialEmptyGuestAccelerator2(cluster, np, networkName, subnetworkName), ExpectNonEmptyPlan: true, PlanOnly: true, }, @@ -1224,6 +1281,8 @@ func TestAccContainerNodePool_shieldedInstanceConfig(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1231,7 +1290,7 @@ func TestAccContainerNodePool_shieldedInstanceConfig(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccContainerNodePool_shieldedInstanceConfig(cluster, np), + Config: testAccContainerNodePool_shieldedInstanceConfig(cluster, np, networkName, subnetworkName), }, resource.TestStep{ ResourceName: "google_container_node_pool.np", @@ -1249,6 +1308,8 @@ func TestAccContainerNodePool_concurrent(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np1 := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) np2 := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1256,7 +1317,7 @@ func TestAccContainerNodePool_concurrent(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_concurrentCreate(cluster, np1, np2), + Config: testAccContainerNodePool_concurrentCreate(cluster, np1, np2, networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.np1", @@ -1269,7 +1330,7 @@ func TestAccContainerNodePool_concurrent(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccContainerNodePool_concurrentUpdate(cluster, np1, np2), + Config: testAccContainerNodePool_concurrentUpdate(cluster, np1, np2, networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.np1", @@ -1286,26 +1347,28 @@ func TestAccContainerNodePool_concurrent(t *testing.T) { } func TestAccContainerNodePool_withSoleTenantConfig(t *testing.T) { - t.Parallel() + t.Parallel() - cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) - np := fmt.Sprintf("tf-test-np-%s", acctest.RandString(t, 10)) + cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) + np := fmt.Sprintf("tf-test-np-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) - acctest.VcrTest(t, resource.TestCase{ - PreCheck: func() { acctest.AccTestPreCheck(t) }, - ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), - CheckDestroy: testAccCheckContainerClusterDestroyProducer(t), - Steps: []resource.TestStep{ - { - Config: testAccContainerNodePool_withSoleTenantConfig(cluster, np), - }, - { - ResourceName: "google_container_node_pool.with_sole_tenant_config", - ImportState: true, - ImportStateVerify: true, - }, - }, - }) + acctest.VcrTest(t, resource.TestCase{ + PreCheck: func() { acctest.AccTestPreCheck(t) }, + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t), + CheckDestroy: testAccCheckContainerClusterDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccContainerNodePool_withSoleTenantConfig(cluster, np, networkName, subnetworkName), + }, + { + ResourceName: "google_container_node_pool.with_sole_tenant_config", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) } @@ -1316,6 +1379,8 @@ func TestAccContainerNodePool_ephemeralStorageConfig(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1323,7 +1388,7 @@ func TestAccContainerNodePool_ephemeralStorageConfig(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccContainerNodePool_ephemeralStorageConfig(cluster, np), + Config: testAccContainerNodePool_ephemeralStorageConfig(cluster, np, networkName, subnetworkName), }, resource.TestStep{ ResourceName: "google_container_node_pool.np", @@ -1334,13 +1399,15 @@ func TestAccContainerNodePool_ephemeralStorageConfig(t *testing.T) { }) } -func testAccContainerNodePool_ephemeralStorageConfig(cluster, np string) string { +func testAccContainerNodePool_ephemeralStorageConfig(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1-a" initial_node_count = 1 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -1356,7 +1423,7 @@ resource "google_container_node_pool" "np" { } } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } <% end %> @@ -1365,6 +1432,8 @@ func TestAccContainerNodePool_ephemeralStorageLocalSsdConfig(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1372,7 +1441,7 @@ func TestAccContainerNodePool_ephemeralStorageLocalSsdConfig(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_ephemeralStorageLocalSsdConfig(cluster, np), + Config: testAccContainerNodePool_ephemeralStorageLocalSsdConfig(cluster, np, networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.np", @@ -1383,7 +1452,7 @@ func TestAccContainerNodePool_ephemeralStorageLocalSsdConfig(t *testing.T) { }) } -func testAccContainerNodePool_ephemeralStorageLocalSsdConfig(cluster, np string) string { +func testAccContainerNodePool_ephemeralStorageLocalSsdConfig(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` data "google_container_engine_versions" "central1a" { location = "us-central1-a" @@ -1397,6 +1466,8 @@ resource "google_container_cluster" "cluster" { min_master_version = data.google_container_engine_versions.central1a.latest_master_version initial_node_count = 1 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -1412,7 +1483,7 @@ resource "google_container_node_pool" "np" { } } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } func TestAccContainerNodePool_localNvmeSsdBlockConfig(t *testing.T) { @@ -1420,6 +1491,8 @@ func TestAccContainerNodePool_localNvmeSsdBlockConfig(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1427,7 +1500,7 @@ func TestAccContainerNodePool_localNvmeSsdBlockConfig(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_localNvmeSsdBlockConfig(cluster, np), + Config: testAccContainerNodePool_localNvmeSsdBlockConfig(cluster, np, networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.np", @@ -1438,7 +1511,7 @@ func TestAccContainerNodePool_localNvmeSsdBlockConfig(t *testing.T) { }) } -func testAccContainerNodePool_localNvmeSsdBlockConfig(cluster, np string) string { +func testAccContainerNodePool_localNvmeSsdBlockConfig(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` data "google_container_engine_versions" "central1a" { location = "us-central1-a" @@ -1452,6 +1525,8 @@ resource "google_container_cluster" "cluster" { min_master_version = data.google_container_engine_versions.central1a.latest_master_version initial_node_count = 1 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -1467,7 +1542,7 @@ resource "google_container_node_pool" "np" { } } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } func TestAccContainerNodePool_gcfsConfig(t *testing.T) { @@ -1475,6 +1550,8 @@ func TestAccContainerNodePool_gcfsConfig(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1482,7 +1559,7 @@ func TestAccContainerNodePool_gcfsConfig(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ resource.TestStep{ - Config: testAccContainerNodePool_gcfsConfig(cluster, np), + Config: testAccContainerNodePool_gcfsConfig(cluster, np, networkName, subnetworkName), }, resource.TestStep{ ResourceName: "google_container_node_pool.np", @@ -1493,13 +1570,15 @@ func TestAccContainerNodePool_gcfsConfig(t *testing.T) { }) } -func testAccContainerNodePool_gcfsConfig(cluster, np string) string { +func testAccContainerNodePool_gcfsConfig(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1-a" initial_node_count = 1 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -1516,7 +1595,7 @@ resource "google_container_node_pool" "np" { } } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } func TestAccContainerNodePool_gvnic(t *testing.T) { @@ -1524,6 +1603,8 @@ func TestAccContainerNodePool_gvnic(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1531,7 +1612,7 @@ func TestAccContainerNodePool_gvnic(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_gvnic(cluster, np), + Config: testAccContainerNodePool_gvnic(cluster, np, networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.np", @@ -1542,13 +1623,15 @@ func TestAccContainerNodePool_gvnic(t *testing.T) { }) } -func testAccContainerNodePool_gvnic(cluster, np string) string { +func testAccContainerNodePool_gvnic(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1-a" initial_node_count = 1 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -1565,7 +1648,7 @@ resource "google_container_node_pool" "np" { } } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } func TestAccContainerNodePool_fastSocket(t *testing.T) { @@ -1573,6 +1656,8 @@ func TestAccContainerNodePool_fastSocket(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1580,7 +1665,7 @@ func TestAccContainerNodePool_fastSocket(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_fastSocket(cluster, np, true), + Config: testAccContainerNodePool_fastSocket(cluster, np, networkName, subnetworkName, true), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("google_container_node_pool.np", "node_config.0.fast_socket.0.enabled", "true"), @@ -1592,7 +1677,7 @@ func TestAccContainerNodePool_fastSocket(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccContainerNodePool_fastSocket(cluster, np, false), + Config: testAccContainerNodePool_fastSocket(cluster, np, networkName, subnetworkName, false), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("google_container_node_pool.np", "node_config.0.fast_socket.0.enabled", "false"), @@ -1607,7 +1692,7 @@ func TestAccContainerNodePool_fastSocket(t *testing.T) { }) } -func testAccContainerNodePool_fastSocket(cluster, np string, enabled bool) string { +func testAccContainerNodePool_fastSocket(cluster, np, networkName, subnetworkName string, enabled bool) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" @@ -1615,6 +1700,8 @@ resource "google_container_cluster" "cluster" { initial_node_count = 1 min_master_version = "1.25" deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -1638,7 +1725,7 @@ resource "google_container_node_pool" "np" { } } } -`, cluster, np, enabled) +`, cluster, networkName, subnetworkName, np, enabled) } func TestAccContainerNodePool_compactPlacement(t *testing.T) { @@ -1646,6 +1733,8 @@ func TestAccContainerNodePool_compactPlacement(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1653,7 +1742,7 @@ func TestAccContainerNodePool_compactPlacement(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_compactPlacement(cluster, np, "COMPACT"), + Config: testAccContainerNodePool_compactPlacement(cluster, np, "COMPACT", networkName, subnetworkName), }, { ResourceName: "google_container_cluster.cluster", @@ -1665,13 +1754,15 @@ func TestAccContainerNodePool_compactPlacement(t *testing.T) { }) } -func testAccContainerNodePool_compactPlacement(cluster, np, placementType string) string { +func testAccContainerNodePool_compactPlacement(cluster, np, placementType, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1-a" initial_node_count = 1 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -1687,7 +1778,7 @@ resource "google_container_node_pool" "np" { type = "%s" } } -`, cluster, np, placementType) +`, cluster, networkName, subnetworkName, np, placementType) } func TestAccContainerNodePool_customPlacementPolicy(t *testing.T) { @@ -1696,6 +1787,8 @@ func TestAccContainerNodePool_customPlacementPolicy(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) policy := fmt.Sprintf("tf-test-policy-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1703,7 +1796,7 @@ func TestAccContainerNodePool_customPlacementPolicy(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_customPlacementPolicy(cluster, np, policy), + Config: testAccContainerNodePool_customPlacementPolicy(cluster, np, policy, networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("google_container_node_pool.np", "node_config.0.machine_type", "c2-standard-4"), resource.TestCheckResourceAttr("google_container_node_pool.np", "placement_policy.0.policy_name", policy), @@ -1719,13 +1812,15 @@ func TestAccContainerNodePool_customPlacementPolicy(t *testing.T) { }) } -func testAccContainerNodePool_customPlacementPolicy(cluster, np, policyName string) string { +func testAccContainerNodePool_customPlacementPolicy(cluster, np, policyName, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1-a" initial_node_count = 1 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_compute_resource_policy" "policy" { @@ -1751,7 +1846,7 @@ resource "google_container_node_pool" "np" { policy_name = google_compute_resource_policy.policy.name } } -`, cluster, policyName, np) +`, cluster, networkName, subnetworkName, policyName, np) } func TestAccContainerNodePool_threadsPerCore(t *testing.T) { @@ -1759,6 +1854,8 @@ func TestAccContainerNodePool_threadsPerCore(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -1766,7 +1863,7 @@ func TestAccContainerNodePool_threadsPerCore(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_threadsPerCore(cluster, np, 1), + Config: testAccContainerNodePool_threadsPerCore(cluster, np, networkName, subnetworkName, 1), }, { ResourceName: "google_container_cluster.cluster", @@ -1778,13 +1875,15 @@ func TestAccContainerNodePool_threadsPerCore(t *testing.T) { }) } -func testAccContainerNodePool_threadsPerCore(cluster, np string, threadsPerCore int) string { +func testAccContainerNodePool_threadsPerCore(cluster, np, networkName, subnetworkName string, threadsPerCore int) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1-a" initial_node_count = 1 deletion_protection = false + network = "%s" + subnetwork = "%s" node_config { machine_type = "c2-standard-4" @@ -1807,7 +1906,7 @@ resource "google_container_node_pool" "np" { } } } -`, cluster, threadsPerCore, np, threadsPerCore) +`, cluster, networkName, subnetworkName, threadsPerCore, np, threadsPerCore) } func testAccCheckContainerNodePoolDestroyProducer(t *testing.T) func(s *terraform.State) error { @@ -1846,7 +1945,7 @@ func testAccCheckContainerNodePoolDestroyProducer(t *testing.T) func(s *terrafor } } -func testAccContainerNodePool_basic(cluster, np string) string { +func testAccContainerNodePool_basic(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` provider "google" { alias = "user-project-override" @@ -1858,6 +1957,8 @@ resource "google_container_cluster" "cluster" { location = "us-central1-a" initial_node_count = 3 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -1867,16 +1968,18 @@ resource "google_container_node_pool" "np" { cluster = google_container_cluster.cluster.name initial_node_count = 2 } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } -func testAccContainerNodePool_withLoggingVariant(cluster, np, loggingVariant string) string { +func testAccContainerNodePool_withLoggingVariant(cluster, np, loggingVariant, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "with_logging_variant" { name = "%s" location = "us-central1-a" initial_node_count = 1 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "with_logging_variant" { @@ -1888,10 +1991,10 @@ resource "google_container_node_pool" "with_logging_variant" { logging_variant = "%s" } } -`, cluster, np, loggingVariant) +`, cluster, networkName, subnetworkName, np, loggingVariant) } -func testAccContainerNodePool_basicWithClusterId(cluster, np string) string { +func testAccContainerNodePool_basicWithClusterId(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` provider "google" { alias = "user-project-override" @@ -1903,6 +2006,8 @@ resource "google_container_cluster" "cluster" { location = "us-central1-a" initial_node_count = 3 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -1911,7 +2016,7 @@ resource "google_container_node_pool" "np" { cluster = google_container_cluster.cluster.id initial_node_count = 2 } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } func testAccContainerNodePool_nodeLocations(cluster, np, network string) string { @@ -2031,13 +2136,15 @@ resource "google_container_node_pool" "np" { `, network, cluster, np) } -func testAccContainerNodePool_regionalClusters(cluster, np string) string { +func testAccContainerNodePool_regionalClusters(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1" initial_node_count = 3 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -2046,16 +2153,18 @@ resource "google_container_node_pool" "np" { location = "us-central1" initial_node_count = 2 } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } -func testAccContainerNodePool_namePrefix(cluster, np string) string { +func testAccContainerNodePool_namePrefix(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1-a" initial_node_count = 3 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -2064,16 +2173,18 @@ resource "google_container_node_pool" "np" { cluster = google_container_cluster.cluster.name initial_node_count = 2 } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } -func testAccContainerNodePool_noName(cluster string) string { +func testAccContainerNodePool_noName(cluster, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1-a" initial_node_count = 3 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -2081,16 +2192,18 @@ resource "google_container_node_pool" "np" { cluster = google_container_cluster.cluster.name initial_node_count = 2 } -`, cluster) +`, cluster, networkName, subnetworkName) } -func testAccContainerNodePool_regionalAutoscaling(cluster, np string) string { +func testAccContainerNodePool_regionalAutoscaling(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1" initial_node_count = 3 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -2103,10 +2216,10 @@ resource "google_container_node_pool" "np" { max_node_count = 3 } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } -func testAccContainerNodePool_totalSize(cluster, np string) string { +func testAccContainerNodePool_totalSize(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" @@ -2114,6 +2227,8 @@ resource "google_container_cluster" "cluster" { initial_node_count = 3 min_master_version = "1.27" deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -2127,10 +2242,10 @@ resource "google_container_node_pool" "np" { location_policy = "BALANCED" } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } -func testAccContainerNodePool_updateTotalSize(cluster, np string) string { +func testAccContainerNodePool_updateTotalSize(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" @@ -2138,6 +2253,8 @@ resource "google_container_cluster" "cluster" { initial_node_count = 3 min_master_version = "1.27" deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -2151,11 +2268,11 @@ resource "google_container_node_pool" "np" { location_policy = "ANY" } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } -func testAccContainerNodePool_basicTotalSize(cluster, np string) string { +func testAccContainerNodePool_basicTotalSize(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` provider "google" { alias = "user-project-override" @@ -2168,6 +2285,8 @@ resource "google_container_cluster" "cluster" { initial_node_count = 3 min_master_version = "1.27" deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -2177,16 +2296,18 @@ resource "google_container_node_pool" "np" { cluster = google_container_cluster.cluster.name initial_node_count = 2 } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } -func testAccContainerNodePool_autoscaling(cluster, np string) string { +func testAccContainerNodePool_autoscaling(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1-a" initial_node_count = 3 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -2199,16 +2320,18 @@ resource "google_container_node_pool" "np" { max_node_count = 3 } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } -func testAccContainerNodePool_updateAutoscaling(cluster, np string) string { +func testAccContainerNodePool_updateAutoscaling(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1-a" initial_node_count = 3 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -2221,10 +2344,10 @@ resource "google_container_node_pool" "np" { max_node_count = 5 } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } -func testAccContainerNodePool_additionalZones(cluster, nodePool string) string { +func testAccContainerNodePool_additionalZones(cluster, nodePool, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" @@ -2236,6 +2359,8 @@ resource "google_container_cluster" "cluster" { "us-central1-c", ] deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -2244,10 +2369,10 @@ resource "google_container_node_pool" "np" { cluster = google_container_cluster.cluster.name node_count = 2 } -`, cluster, nodePool) +`, cluster, networkName, subnetworkName, nodePool) } -func testAccContainerNodePool_resize(cluster, nodePool string) string { +func testAccContainerNodePool_resize(cluster, nodePool, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" @@ -2259,6 +2384,8 @@ resource "google_container_cluster" "cluster" { "us-central1-c", ] deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -2267,10 +2394,10 @@ resource "google_container_node_pool" "np" { cluster = google_container_cluster.cluster.name node_count = 3 } -`, cluster, nodePool) +`, cluster, networkName, subnetworkName, nodePool) } -func testAccContainerNodePool_withManagement(cluster, nodePool, management string) string { +func testAccContainerNodePool_withManagement(cluster, nodePool, management, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" @@ -2280,6 +2407,8 @@ resource "google_container_cluster" "cluster" { channel = "UNSPECIFIED" } deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np_with_management" { @@ -2296,16 +2425,18 @@ resource "google_container_node_pool" "np_with_management" { oauth_scopes = ["compute-rw", "storage-ro", "logging-write", "monitoring"] } } -`, cluster, nodePool, management) +`, cluster, networkName, subnetworkName, nodePool, management) } -func testAccContainerNodePool_withNodeConfig(cluster, nodePool string) string { +func testAccContainerNodePool_withNodeConfig(cluster, nodePool, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1-a" initial_node_count = 1 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np_with_node_config" { @@ -2351,16 +2482,18 @@ resource "google_container_node_pool" "np_with_node_config" { } } } -`, cluster, nodePool) +`, cluster, networkName, subnetworkName, nodePool) } -func testAccContainerNodePool_withNodeConfigUpdate(cluster, nodePool string) string { +func testAccContainerNodePool_withNodeConfigUpdate(cluster, nodePool, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1-a" initial_node_count = 1 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np_with_node_config" { @@ -2408,10 +2541,10 @@ resource "google_container_node_pool" "np_with_node_config" { } } } -`, cluster, nodePool) +`, cluster, networkName, subnetworkName, nodePool) } -func testAccContainerNodePool_withTaintsUpdate(cluster, np string) string { +func testAccContainerNodePool_withTaintsUpdate(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` provider "google" { alias = "user-project-override" @@ -2423,6 +2556,8 @@ resource "google_container_cluster" "cluster" { location = "us-central1-a" initial_node_count = 3 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -2442,10 +2577,10 @@ resource "google_container_node_pool" "np" { } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } -func testAccContainerNodePool_withReservationAffinity(cluster, np string) string { +func testAccContainerNodePool_withReservationAffinity(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` data "google_container_engine_versions" "central1a" { location = "us-central1-a" @@ -2457,6 +2592,8 @@ resource "google_container_cluster" "cluster" { initial_node_count = 1 min_master_version = data.google_container_engine_versions.central1a.latest_master_version deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "with_reservation_affinity" { @@ -2475,10 +2612,10 @@ resource "google_container_node_pool" "with_reservation_affinity" { } } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } -func testAccContainerNodePool_withReservationAffinitySpecific(cluster, reservation, np string) string { +func testAccContainerNodePool_withReservationAffinitySpecific(cluster, reservation, np, networkName, subnetworkName string) string { return fmt.Sprintf(` data "google_container_engine_versions" "central1a" { location = "us-central1-a" @@ -2490,6 +2627,8 @@ resource "google_container_cluster" "cluster" { initial_node_count = 1 min_master_version = data.google_container_engine_versions.central1a.latest_master_version deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_compute_reservation" "gce_reservation" { @@ -2526,11 +2665,11 @@ resource "google_container_node_pool" "with_reservation_affinity" { } } } -`, cluster, reservation, np) +`, cluster, networkName, subnetworkName, reservation, np) } -func testAccContainerNodePool_withWorkloadMetadataConfig(cluster, np string) string { +func testAccContainerNodePool_withWorkloadMetadataConfig(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` data "google_container_engine_versions" "central1a" { location = "us-central1-a" @@ -2542,6 +2681,8 @@ resource "google_container_cluster" "cluster" { initial_node_count = 1 min_master_version = data.google_container_engine_versions.central1a.latest_master_version deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "with_workload_metadata_config" { @@ -2561,10 +2702,10 @@ resource "google_container_node_pool" "with_workload_metadata_config" { } } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } -func testAccContainerNodePool_withWorkloadMetadataConfig_gkeMetadata(projectID, cluster, np string) string { +func testAccContainerNodePool_withWorkloadMetadataConfig_gkeMetadata(projectID, cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` data "google_project" "project" { project_id = "%s" @@ -2584,6 +2725,8 @@ resource "google_container_cluster" "cluster" { workload_pool = "${data.google_project.project.project_id}.svc.id.goog" } deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "with_workload_metadata_config" { @@ -2602,11 +2745,11 @@ resource "google_container_node_pool" "with_workload_metadata_config" { } } } -`, projectID, cluster, np) +`, projectID, cluster, networkName, subnetworkName, np) } <% unless version.nil? || version == 'ga' -%> -func testAccContainerNodePool_withSandboxConfig(cluster, np string) string { +func testAccContainerNodePool_withSandboxConfig(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` data "google_container_engine_versions" "central1a" { location = "us-central1-a" @@ -2618,6 +2761,8 @@ resource "google_container_cluster" "cluster" { initial_node_count = 1 min_master_version = data.google_container_engine_versions.central1a.latest_master_version deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "with_sandbox_config" { @@ -2643,11 +2788,11 @@ resource "google_container_node_pool" "with_sandbox_config" { ] } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } <% end -%> -func testAccContainerNodePool_withKubeletConfig(cluster, np, policy, period string, quota bool, podPidsLimit int) string { +func testAccContainerNodePool_withKubeletConfig(cluster, np, policy, period, networkName, subnetworkName string, quota bool, podPidsLimit int) string { return fmt.Sprintf(` data "google_container_engine_versions" "central1a" { location = "us-central1-a" @@ -2659,6 +2804,8 @@ resource "google_container_cluster" "cluster" { initial_node_count = 1 min_master_version = data.google_container_engine_versions.central1a.latest_master_version deletion_protection = false + network = "%s" + subnetwork = "%s" } # cpu_manager_policy & cpu_cfs_quota_period cannot be blank if cpu_cfs_quota is set to true @@ -2683,10 +2830,10 @@ resource "google_container_node_pool" "with_kubelet_config" { logging_variant = "DEFAULT" } } -`, cluster, np, policy, quota, period, podPidsLimit) +`, cluster, networkName, subnetworkName, np, policy, quota, period, podPidsLimit) } -func testAccContainerNodePool_withLinuxNodeConfig(cluster, np string, tcpMem string) string { +func testAccContainerNodePool_withLinuxNodeConfig(cluster, np, tcpMem, networkName, subnetworkName string) string { linuxNodeConfig := ` linux_node_config { sysctls = {} @@ -2721,6 +2868,8 @@ resource "google_container_cluster" "cluster" { initial_node_count = 1 min_master_version = data.google_container_engine_versions.central1a.latest_master_version deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "with_linux_node_config" { @@ -2737,10 +2886,10 @@ resource "google_container_node_pool" "with_linux_node_config" { ] } } -`, cluster, np, linuxNodeConfig) +`, cluster, networkName, subnetworkName, np, linuxNodeConfig) } -func testAccContainerNodePool_withCgroupMode(cluster, np string, mode string) string { +func testAccContainerNodePool_withCgroupMode(cluster, np, mode, networkName, subnetworkName string) string { return fmt.Sprintf(` data "google_container_engine_versions" "central1a" { location = "us-central1-a" @@ -2752,6 +2901,8 @@ resource "google_container_cluster" "cluster" { initial_node_count = 1 min_master_version = data.google_container_engine_versions.central1a.latest_master_version deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -2770,7 +2921,7 @@ resource "google_container_node_pool" "np" { ] } } -`, cluster, np, mode) +`, cluster, networkName, subnetworkName, np, mode) } func testAccContainerNodePool_withNetworkConfig(cluster, np, network string) string { @@ -3002,7 +3153,7 @@ resource "google_container_node_pool" "with_multi_nic" { <% end -%> <% unless version.nil? || version == 'ga' -%> -func testAccContainerNodePool_withBootDiskKmsKey(cluster, np string) string { +func testAccContainerNodePool_withBootDiskKmsKey(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` data "google_container_engine_versions" "central1a" { location = "us-central1-a" @@ -3025,6 +3176,8 @@ resource "google_container_cluster" "cluster" { initial_node_count = 1 min_master_version = data.google_container_engine_versions.central1a.latest_master_version deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "with_boot_disk_kms_key" { @@ -3042,7 +3195,7 @@ resource "google_container_node_pool" "with_boot_disk_kms_key" { ] } } -`, cluster, cluster, cluster, np) +`, cluster, cluster, cluster, networkName, subnetworkName, np) } <% end -%> @@ -3071,7 +3224,7 @@ upgrade_settings { `, maxSurge, maxUnavailable, strategy) } -func testAccContainerNodePool_withUpgradeSettings(clusterName string, nodePoolName string, maxSurge int, maxUnavailable int, strategy string, nodePoolSoakDuration string, batchNodeCount int, batchPercentage float64, batchSoakDuration string) string { +func testAccContainerNodePool_withUpgradeSettings(clusterName, nodePoolName, networkName, subnetworkName string, maxSurge int, maxUnavailable int, strategy string, nodePoolSoakDuration string, batchNodeCount int, batchPercentage float64, batchSoakDuration string) string { return fmt.Sprintf(` data "google_container_engine_versions" "central1" { location = "us-central1" @@ -3083,6 +3236,8 @@ resource "google_container_cluster" "cluster" { initial_node_count = 1 min_master_version = "${data.google_container_engine_versions.central1.latest_master_version}" deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "with_upgrade_settings" { @@ -3092,10 +3247,10 @@ resource "google_container_node_pool" "with_upgrade_settings" { initial_node_count = 1 %s } -`, clusterName, nodePoolName, makeUpgradeSettings(maxSurge, maxUnavailable, strategy, nodePoolSoakDuration, batchNodeCount, batchPercentage, batchSoakDuration)) +`, clusterName, networkName, subnetworkName, nodePoolName, makeUpgradeSettings(maxSurge, maxUnavailable, strategy, nodePoolSoakDuration, batchNodeCount, batchPercentage, batchSoakDuration)) } -func testAccContainerNodePool_withGPU(cluster, np string) string { +func testAccContainerNodePool_withGPU(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` data "google_container_engine_versions" "central1c" { location = "us-central1-c" @@ -3107,6 +3262,8 @@ resource "google_container_cluster" "cluster" { initial_node_count = 1 min_master_version = data.google_container_engine_versions.central1c.latest_master_version deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np_with_gpu" { @@ -3147,16 +3304,18 @@ resource "google_container_node_pool" "np_with_gpu" { } } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } -func testAccContainerNodePool_withNodeConfigScopeAlias(cluster, np string) string { +func testAccContainerNodePool_withNodeConfigScopeAlias(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1-a" initial_node_count = 1 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np_with_node_config_scope_alias" { @@ -3170,10 +3329,10 @@ resource "google_container_node_pool" "np_with_node_config_scope_alias" { oauth_scopes = ["compute-rw", "storage-ro", "logging-write", "monitoring"] } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } -func testAccContainerNodePool_version(cluster, np string) string { +func testAccContainerNodePool_version(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` data "google_container_engine_versions" "central1a" { location = "us-central1-a" @@ -3185,6 +3344,8 @@ resource "google_container_cluster" "cluster" { initial_node_count = 1 min_master_version = data.google_container_engine_versions.central1a.latest_master_version deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -3195,10 +3356,10 @@ resource "google_container_node_pool" "np" { version = data.google_container_engine_versions.central1a.valid_node_versions[1] } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } -func testAccContainerNodePool_updateVersion(cluster, np string) string { +func testAccContainerNodePool_updateVersion(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` data "google_container_engine_versions" "central1a" { location = "us-central1-a" @@ -3210,6 +3371,8 @@ resource "google_container_cluster" "cluster" { initial_node_count = 1 min_master_version = data.google_container_engine_versions.central1a.latest_master_version deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -3220,16 +3383,18 @@ resource "google_container_node_pool" "np" { version = data.google_container_engine_versions.central1a.valid_node_versions[0] } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } -func testAccContainerNodePool_012_ConfigModeAttr1(cluster, np string) string { +func testAccContainerNodePool_012_ConfigModeAttr1(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1-f" initial_node_count = 3 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -3246,16 +3411,18 @@ resource "google_container_node_pool" "np" { machine_type = "n1-highmem-4" } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } -func testAccContainerNodePool_012_ConfigModeAttr2(cluster, np string) string { +func testAccContainerNodePool_012_ConfigModeAttr2(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1-f" initial_node_count = 3 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -3268,16 +3435,18 @@ resource "google_container_node_pool" "np" { guest_accelerator = [] } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } -func testAccContainerNodePool_EmptyGuestAccelerator(cluster, np string) string { +func testAccContainerNodePool_EmptyGuestAccelerator(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1-f" initial_node_count = 3 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -3294,16 +3463,18 @@ resource "google_container_node_pool" "np" { machine_type = "n1-highmem-4" } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } -func testAccContainerNodePool_PartialEmptyGuestAccelerator(cluster, np string, count int) string { +func testAccContainerNodePool_PartialEmptyGuestAccelerator(cluster, np, networkName, subnetworkName string, count int) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1-f" initial_node_count = 3 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -3325,16 +3496,18 @@ resource "google_container_node_pool" "np" { machine_type = "n1-highmem-4" } } -`, cluster, np, count) +`, cluster, networkName, subnetworkName, np, count) } -func testAccContainerNodePool_PartialEmptyGuestAccelerator2(cluster, np string) string { +func testAccContainerNodePool_PartialEmptyGuestAccelerator2(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1-f" initial_node_count = 3 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -3361,16 +3534,18 @@ resource "google_container_node_pool" "np" { machine_type = "n1-highmem-4" } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } -func testAccContainerNodePool_shieldedInstanceConfig(cluster, np string) string { +func testAccContainerNodePool_shieldedInstanceConfig(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1-a" initial_node_count = 1 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { @@ -3385,16 +3560,18 @@ resource "google_container_node_pool" "np" { } } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } -func testAccContainerNodePool_concurrentCreate(cluster, np1, np2 string) string { +func testAccContainerNodePool_concurrentCreate(cluster, np1, np2, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1-a" initial_node_count = 3 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np1" { @@ -3410,16 +3587,18 @@ resource "google_container_node_pool" "np2" { cluster = google_container_cluster.cluster.name initial_node_count = 2 } -`, cluster, np1, np2) +`, cluster, networkName, subnetworkName, np1, np2) } -func testAccContainerNodePool_concurrentUpdate(cluster, np1, np2 string) string { +func testAccContainerNodePool_concurrentUpdate(cluster, np1, np2, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" location = "us-central1-a" initial_node_count = 3 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np1" { @@ -3437,10 +3616,10 @@ resource "google_container_node_pool" "np2" { initial_node_count = 2 version = "1.27.3-gke.1700" } -`, cluster, np1, np2) +`, cluster, networkName, subnetworkName, np1, np2) } -func testAccContainerNodePool_withSoleTenantConfig(cluster, np string) string { +func testAccContainerNodePool_withSoleTenantConfig(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` data "google_container_engine_versions" "central1a" { location = "us-central1-a" @@ -3465,6 +3644,8 @@ resource "google_container_cluster" "cluster" { initial_node_count = 1 min_master_version = data.google_container_engine_versions.central1a.latest_master_version deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "with_sole_tenant_config" { @@ -3487,7 +3668,7 @@ resource "google_container_node_pool" "with_sole_tenant_config" { ] } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } func TestAccContainerNodePool_withConfidentialNodes(t *testing.T) { @@ -3495,6 +3676,8 @@ func TestAccContainerNodePool_withConfidentialNodes(t *testing.T) { clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-cluster-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -3502,7 +3685,7 @@ func TestAccContainerNodePool_withConfidentialNodes(t *testing.T) { CheckDestroy: testAccCheckContainerClusterDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_withConfidentialNodes(clusterName, np), + Config: testAccContainerNodePool_withConfidentialNodes(clusterName, np, networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.np", @@ -3510,7 +3693,7 @@ func TestAccContainerNodePool_withConfidentialNodes(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccContainerNodePool_disableConfidentialNodes(clusterName, np), + Config: testAccContainerNodePool_disableConfidentialNodes(clusterName, np, networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.np", @@ -3518,7 +3701,7 @@ func TestAccContainerNodePool_withConfidentialNodes(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccContainerNodePool_withConfidentialNodes(clusterName, np), + Config: testAccContainerNodePool_withConfidentialNodes(clusterName, np, networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.np", @@ -3529,11 +3712,11 @@ func TestAccContainerNodePool_withConfidentialNodes(t *testing.T) { }) } -func testAccContainerNodePool_withConfidentialNodes(clusterName string, np string) string { +func testAccContainerNodePool_withConfidentialNodes(clusterName, np, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" - location = "asia-east1-c" + location = "us-central1-a" initial_node_count = 1 node_config { confidential_nodes { @@ -3542,11 +3725,13 @@ resource "google_container_cluster" "cluster" { machine_type = "n2-standard-2" } deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { name = "%s" - location = "asia-east1-c" + location = "us-central1-a" cluster = google_container_cluster.cluster.name initial_node_count = 1 node_config { @@ -3556,14 +3741,14 @@ resource "google_container_node_pool" "np" { } } } -`, clusterName, np) +`, clusterName, networkName, subnetworkName, np) } -func testAccContainerNodePool_disableConfidentialNodes(clusterName string, np string) string { +func testAccContainerNodePool_disableConfidentialNodes(clusterName, np, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" - location = "asia-east1-c" + location = "us-central1-a" initial_node_count = 1 node_config { confidential_nodes { @@ -3572,11 +3757,13 @@ resource "google_container_cluster" "cluster" { machine_type = "n2-standard-2" } deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "np" { name = "%s" - location = "asia-east1-c" + location = "us-central1-a" cluster = google_container_cluster.cluster.name initial_node_count = 1 node_config { @@ -3586,7 +3773,7 @@ resource "google_container_node_pool" "np" { } } } -`, clusterName, np) +`, clusterName, networkName, subnetworkName, np) } func TestAccContainerNodePool_tpuTopology(t *testing.T) { @@ -3596,6 +3783,8 @@ func TestAccContainerNodePool_tpuTopology(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np1 := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) np2 := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -3603,7 +3792,7 @@ func TestAccContainerNodePool_tpuTopology(t *testing.T) { CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_tpuTopology(cluster, np1, np2, "2x2x2"), + Config: testAccContainerNodePool_tpuTopology(cluster, np1, np2, "2x2x2", networkName, subnetworkName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("google_container_node_pool.regular_pool", "node_config.0.machine_type", "n1-standard-4"), resource.TestCheckResourceAttr("google_container_node_pool.with_tpu_topology", "node_config.0.machine_type", "ct4p-hightpu-4t"), @@ -3620,30 +3809,31 @@ func TestAccContainerNodePool_tpuTopology(t *testing.T) { }) } -func testAccContainerNodePool_tpuTopology(cluster, np1, np2, tpuTopology string) string { +func testAccContainerNodePool_tpuTopology(cluster, np1, np2, tpuTopology, networkName, subnetworkName string) string { return fmt.Sprintf(` resource "google_container_cluster" "cluster" { name = "%s" - location = "us-central2-b" + location = "us-central1-a" initial_node_count = 1 deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "regular_pool" { - name = "%s" - location = "us-central2-b" - cluster = google_container_cluster.cluster.name - initial_node_count = 1 - - node_config { - machine_type = "n1-standard-4" + name = "%s" + location = "us-central1-a" + cluster = google_container_cluster.cluster.name + initial_node_count = 1 - } + node_config { + machine_type = "n1-standard-4" } +} resource "google_container_node_pool" "with_tpu_topology" { name = "%s" - location = "us-central2-b" + location = "us-central1-a" cluster = google_container_cluster.cluster.name initial_node_count = 2 @@ -3652,11 +3842,11 @@ resource "google_container_node_pool" "with_tpu_topology" { } placement_policy { - type = "COMPACT" - tpu_topology = "%s" + type = "COMPACT" + tpu_topology = "%s" } } -`, cluster, np1, np2, tpuTopology) +`, cluster, networkName, subnetworkName, np1, np2, tpuTopology) } <% unless version == 'ga' -%> @@ -3722,6 +3912,8 @@ func TestAccContainerNodePool_withConfidentialBootDisk(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-np-%s", acctest.RandString(t, 10)) kms := acctest.BootstrapKMSKeyInLocation(t, "us-central1") + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) if acctest.BootstrapPSARole(t, "service-", "compute-system", "roles/cloudkms.cryptoKeyEncrypterDecrypter") { t.Fatal("Stopping the test because a role was added to the policy.") @@ -3733,7 +3925,7 @@ func TestAccContainerNodePool_withConfidentialBootDisk(t *testing.T) { CheckDestroy: testAccCheckContainerClusterDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_withConfidentialBootDisk(cluster, np, kms.CryptoKey.Name), + Config: testAccContainerNodePool_withConfidentialBootDisk(cluster, np, kms.CryptoKey.Name, networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.with_confidential_boot_disk", @@ -3744,38 +3936,40 @@ func TestAccContainerNodePool_withConfidentialBootDisk(t *testing.T) { }) } -func testAccContainerNodePool_withConfidentialBootDisk(cluster, np string, kmsKeyName string) string { +func testAccContainerNodePool_withConfidentialBootDisk(cluster, np string, kmsKeyName, networkName, subnetworkName string) string { return fmt.Sprintf(` data "google_container_engine_versions" "central1a" { location = "us-central1-a" } resource "google_container_cluster" "cluster" { - name = "%s" - location = "us-central1-a" - initial_node_count = 1 - min_master_version = data.google_container_engine_versions.central1a.latest_master_version - deletion_protection = false + name = "%s" + location = "us-central1-a" + initial_node_count = 1 + min_master_version = data.google_container_engine_versions.central1a.latest_master_version + deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "with_confidential_boot_disk" { - name = "%s" - location = "us-central1-a" - cluster = google_container_cluster.cluster.name - -node_config { - image_type = "COS_CONTAINERD" - boot_disk_kms_key = "%s" - oauth_scopes = [ + name = "%s" + location = "us-central1-a" + cluster = google_container_cluster.cluster.name + + node_config { + image_type = "COS_CONTAINERD" + boot_disk_kms_key = "%s" + oauth_scopes = [ "https://www.googleapis.com/auth/logging.write", "https://www.googleapis.com/auth/monitoring", ] - enable_confidential_storage = true - machine_type = "n2-standard-2" - disk_type = "hyperdisk-balanced" + enable_confidential_storage = true + machine_type = "n2-standard-2" + disk_type = "hyperdisk-balanced" } } -`, cluster, np, kmsKeyName) +`, cluster, networkName, subnetworkName, np, kmsKeyName) } func TestAccContainerNodePool_withoutConfidentialBootDisk(t *testing.T) { @@ -3783,6 +3977,8 @@ func TestAccContainerNodePool_withoutConfidentialBootDisk(t *testing.T) { cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10)) np := fmt.Sprintf("tf-test-np-%s", acctest.RandString(t, 10)) + networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster") + subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName) acctest.VcrTest(t, resource.TestCase{ PreCheck: func() { acctest.AccTestPreCheck(t) }, @@ -3790,7 +3986,7 @@ func TestAccContainerNodePool_withoutConfidentialBootDisk(t *testing.T) { CheckDestroy: testAccCheckContainerClusterDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccContainerNodePool_withoutConfidentialBootDisk(cluster, np), + Config: testAccContainerNodePool_withoutConfidentialBootDisk(cluster, np, networkName, subnetworkName), }, { ResourceName: "google_container_node_pool.without_confidential_boot_disk", @@ -3801,36 +3997,38 @@ func TestAccContainerNodePool_withoutConfidentialBootDisk(t *testing.T) { }) } -func testAccContainerNodePool_withoutConfidentialBootDisk(cluster, np string) string { +func testAccContainerNodePool_withoutConfidentialBootDisk(cluster, np, networkName, subnetworkName string) string { return fmt.Sprintf(` data "google_container_engine_versions" "central1a" { location = "us-central1-a" } resource "google_container_cluster" "cluster" { - name = "%s" - location = "us-central1-a" - initial_node_count = 1 - min_master_version = data.google_container_engine_versions.central1a.latest_master_version - deletion_protection = false + name = "%s" + location = "us-central1-a" + initial_node_count = 1 + min_master_version = data.google_container_engine_versions.central1a.latest_master_version + deletion_protection = false + network = "%s" + subnetwork = "%s" } resource "google_container_node_pool" "without_confidential_boot_disk" { - name = "%s" - location = "us-central1-a" - cluster = google_container_cluster.cluster.name - - node_config { - image_type = "COS_CONTAINERD" - oauth_scopes = [ + name = "%s" + location = "us-central1-a" + cluster = google_container_cluster.cluster.name + + node_config { + image_type = "COS_CONTAINERD" + oauth_scopes = [ "https://www.googleapis.com/auth/logging.write", "https://www.googleapis.com/auth/monitoring", ] - enable_confidential_storage = false - machine_type = "n2-standard-2" - disk_type = "pd-balanced" + enable_confidential_storage = false + machine_type = "n2-standard-2" + disk_type = "pd-balanced" } } -`, cluster, np) +`, cluster, networkName, subnetworkName, np) } <% end -%> \ No newline at end of file