@@ -4170,10 +4170,14 @@ func TestAccContainerCluster_nodeAutoprovisioning(t *testing.T) {
41704170 ),
41714171 },
41724172 {
4173- ResourceName: "google_container_cluster.with_autoprovisioning",
4174- ImportState: true,
4175- ImportStateVerify: true,
4176- ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
4173+ ResourceName: "google_container_cluster.with_autoprovisioning",
4174+ ImportState: true,
4175+ ImportStateVerify: true,
4176+ ImportStateVerifyIgnore: []string{
4177+ "min_master_version",
4178+ "deletion_protection",
4179+ "node_pool", // cluster_autoscaling (node auto-provisioning) creates new node pools automatically
4180+ },
41774181 },
41784182 {
41794183 Config: testAccContainerCluster_autoprovisioning(clusterName, networkName, subnetworkName, true, false, true),
@@ -4187,10 +4191,14 @@ func TestAccContainerCluster_nodeAutoprovisioning(t *testing.T) {
41874191 ),
41884192 },
41894193 {
4190- ResourceName: "google_container_cluster.with_autoprovisioning",
4191- ImportState: true,
4192- ImportStateVerify: true,
4193- ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
4194+ ResourceName: "google_container_cluster.with_autoprovisioning",
4195+ ImportState: true,
4196+ ImportStateVerify: true,
4197+ ImportStateVerifyIgnore: []string{
4198+ "min_master_version",
4199+ "deletion_protection",
4200+ "node_pool",
4201+ },
41944202 },
41954203 {
41964204 Config: testAccContainerCluster_autoprovisioning(clusterName, networkName, subnetworkName, false, false, false),
@@ -4205,10 +4213,14 @@ func TestAccContainerCluster_nodeAutoprovisioning(t *testing.T) {
42054213 ),
42064214 },
42074215 {
4208- ResourceName: "google_container_cluster.with_autoprovisioning",
4209- ImportState: true,
4210- ImportStateVerify: true,
4211- ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
4216+ ResourceName: "google_container_cluster.with_autoprovisioning",
4217+ ImportState: true,
4218+ ImportStateVerify: true,
4219+ ImportStateVerifyIgnore: []string{
4220+ "min_master_version",
4221+ "deletion_protection",
4222+ "node_pool",
4223+ },
42124224 },
42134225 },
42144226 })
@@ -4238,7 +4250,7 @@ func TestAccContainerCluster_nodeAutoprovisioningDefaults(t *testing.T) {
42384250 ResourceName: "google_container_cluster.with_autoprovisioning",
42394251 ImportState: true,
42404252 ImportStateVerify: true,
4241- ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
4253+ ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection", "node_pool" },
42424254 },
42434255 {
42444256 Config: testAccContainerCluster_autoprovisioningDefaults(clusterName, networkName, subnetworkName, true),
@@ -4252,7 +4264,7 @@ func TestAccContainerCluster_nodeAutoprovisioningDefaults(t *testing.T) {
42524264 ResourceName: "google_container_cluster.with_autoprovisioning",
42534265 ImportState: true,
42544266 ImportStateVerify: true,
4255- ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
4267+ ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection", "node_pool" },
42564268 },
42574269 {
42584270 Config: testAccContainerCluster_autoprovisioningDefaultsMinCpuPlatform(clusterName, networkName, subnetworkName, !includeMinCpuPlatform),
@@ -4261,7 +4273,7 @@ func TestAccContainerCluster_nodeAutoprovisioningDefaults(t *testing.T) {
42614273 ResourceName: "google_container_cluster.with_autoprovisioning",
42624274 ImportState: true,
42634275 ImportStateVerify: true,
4264- ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
4276+ ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection", "node_pool" },
42654277 },
42664278 },
42674279 })
@@ -4286,7 +4298,7 @@ func TestAccContainerCluster_autoprovisioningDefaultsUpgradeSettings(t *testing.
42864298 ResourceName: "google_container_cluster.with_autoprovisioning_upgrade_settings",
42874299 ImportState: true,
42884300 ImportStateVerify: true,
4289- ImportStateVerifyIgnore: []string{"deletion_protection"},
4301+ ImportStateVerifyIgnore: []string{"deletion_protection", "node_pool" },
42904302 },
42914303 {
42924304 Config: testAccContainerCluster_autoprovisioningDefaultsUpgradeSettings(clusterName, networkName, subnetworkName, 2, 1, "BLUE_GREEN"),
@@ -4299,7 +4311,7 @@ func TestAccContainerCluster_autoprovisioningDefaultsUpgradeSettings(t *testing.
42994311 ResourceName: "google_container_cluster.with_autoprovisioning_upgrade_settings",
43004312 ImportState: true,
43014313 ImportStateVerify: true,
4302- ImportStateVerifyIgnore: []string{"deletion_protection"},
4314+ ImportStateVerifyIgnore: []string{"deletion_protection", "node_pool" },
43034315 },
43044316 },
43054317 })
@@ -4328,7 +4340,7 @@ func TestAccContainerCluster_nodeAutoprovisioningNetworkTags(t *testing.T) {
43284340 ResourceName: "google_container_cluster.with_autoprovisioning",
43294341 ImportState: true,
43304342 ImportStateVerify: true,
4331- ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
4343+ ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection", "node_pool" },
43324344 },
43334345 },
43344346 })
@@ -4342,12 +4354,12 @@ func TestAccContainerCluster_withDefaultComputeClassEnabled(t *testing.T) {
43424354 subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
43434355
43444356 acctest.VcrTest(t, resource.TestCase{
4345- PreCheck: func() { acctest.AccTestPreCheck(t) },
4357+ PreCheck: func() { acctest.AccTestPreCheck(t) },
43464358 ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
4347- CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
4359+ CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
43484360 Steps: []resource.TestStep{
43494361 {
4350- Config: testAccContainerCluster_withDefaultComputeClassEnabled(clusterName, networkName, subnetworkName, true),
4362+ Config: testAccContainerCluster_withDefaultComputeClassEnabled(clusterName, networkName, subnetworkName, true, false ),
43514363 Check: resource.ComposeTestCheckFunc(
43524364 resource.TestCheckResourceAttr("google_container_cluster.primary", "cluster_autoscaling.0.default_compute_class_enabled", "true"),
43534365 ),
@@ -4356,10 +4368,10 @@ func TestAccContainerCluster_withDefaultComputeClassEnabled(t *testing.T) {
43564368 ResourceName: "google_container_cluster.primary",
43574369 ImportState: true,
43584370 ImportStateVerify: true,
4359- ImportStateVerifyIgnore: []string{"deletion_protection"},
4371+ ImportStateVerifyIgnore: []string{"deletion_protection", "node_pool" },
43604372 },
43614373 {
4362- Config: testAccContainerCluster_withDefaultComputeClassEnabled(clusterName, networkName, subnetworkName, false),
4374+ Config: testAccContainerCluster_withDefaultComputeClassEnabled(clusterName, networkName, subnetworkName, false, false ),
43634375 Check: resource.ComposeTestCheckFunc(
43644376 resource.TestCheckResourceAttr("google_container_cluster.primary", "cluster_autoscaling.0.default_compute_class_enabled", "false"),
43654377 ),
@@ -4368,25 +4380,82 @@ func TestAccContainerCluster_withDefaultComputeClassEnabled(t *testing.T) {
43684380 ResourceName: "google_container_cluster.primary",
43694381 ImportState: true,
43704382 ImportStateVerify: true,
4371- ImportStateVerifyIgnore: []string{"deletion_protection"},
4383+ ImportStateVerifyIgnore: []string{"deletion_protection", "node_pool" },
43724384 },
43734385 },
43744386 })
43754387}
43764388
4377- func testAccContainerCluster_withDefaultComputeClassEnabled(clusterName, networkName, subnetworkName string, enabled bool) string {
4378- return fmt.Sprintf(`
4389+ func TestAccContainerCluster_withAutopilotDefaultComputeClassEnabled(t *testing.T) {
4390+ t.Parallel()
4391+
4392+ clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
4393+ networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
4394+ subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
4395+
4396+ acctest.VcrTest(t, resource.TestCase{
4397+ PreCheck: func() { acctest.AccTestPreCheck(t) },
4398+ ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
4399+ CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
4400+ Steps: []resource.TestStep{
4401+ {
4402+ Config: testAccContainerCluster_withDefaultComputeClassEnabled(clusterName, networkName, subnetworkName, true, true),
4403+ Check: resource.ComposeTestCheckFunc(
4404+ resource.TestCheckResourceAttr("google_container_cluster.primary", "cluster_autoscaling.0.default_compute_class_enabled", "true"),
4405+ ),
4406+ },
4407+ {
4408+ ResourceName: "google_container_cluster.primary",
4409+ ImportState: true,
4410+ ImportStateVerify: true,
4411+ ImportStateVerifyIgnore: []string{"deletion_protection", "node_pool"},
4412+ },
4413+ {
4414+ Config: testAccContainerCluster_withDefaultComputeClassEnabled(clusterName, networkName, subnetworkName, false, true),
4415+ Check: resource.ComposeTestCheckFunc(
4416+ resource.TestCheckResourceAttr("google_container_cluster.primary", "cluster_autoscaling.0.default_compute_class_enabled", "false"),
4417+ ),
4418+ },
4419+ {
4420+ ResourceName: "google_container_cluster.primary",
4421+ ImportState: true,
4422+ ImportStateVerify: true,
4423+ ImportStateVerifyIgnore: []string{"deletion_protection", "node_pool"},
4424+ },
4425+ },
4426+ })
4427+ }
4428+
4429+ func testAccContainerCluster_withDefaultComputeClassEnabled(clusterName, networkName, subnetworkName string, enabled, autopilot bool) string {
4430+ var location string
4431+ if autopilot {
4432+ location = "us-central1"
4433+ } else {
4434+ location = "us-central1-a"
4435+ }
4436+ res := fmt.Sprintf(`
43794437resource "google_container_cluster" "primary" {
43804438 name = "%s"
4381- location = "us-central1-a "
4439+ location = "%s "
43824440 initial_node_count = 1
43834441 network = "%s"
43844442 subnetwork = "%s"
43854443 deletion_protection = false
4444+ `, clusterName, location, networkName, subnetworkName)
43864445
4446+ if autopilot {
4447+ res += `
4448+ enable_autopilot = true
4449+ `
4450+ }
4451+
4452+ res += fmt.Sprintf(`
43874453 cluster_autoscaling {
4388- enabled = true
43894454 default_compute_class_enabled = %t
4455+ `, enabled)
4456+ if !autopilot {
4457+ res += `
4458+ enabled = true
43904459 resource_limits {
43914460 resource_type = "cpu"
43924461 minimum = 1
@@ -4397,9 +4466,12 @@ resource "google_container_cluster" "primary" {
43974466 minimum = 10
43984467 maximum = 100
43994468 }
4469+ `
4470+ }
4471+ res += `
44004472 }
4401- }
4402- `, clusterName, networkName, subnetworkName, enabled)
4473+ }`
4474+ return res
44034475}
44044476
44054477
0 commit comments