Skip to content

Commit ae027fc

Browse files
committed
2 parents 5dbf730 + c99c316 commit ae027fc

4 files changed

Lines changed: 145 additions & 50 deletions

File tree

mmv1/products/spanner/Instance.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ virtual_fields:
7474
This must be set to true if you created a backup manually in the console.
7575
type: Boolean
7676
default_value: false
77+
tgc_tests:
78+
- name: 'TestAccSpannerInstance_basicWithAutoscalingUsingNodeConfigUpdateDisableAutoscaling'
79+
skip: 'sometimes the CAI asset data for step3 is unavailable'
7780
parameters:
7881
properties:
7982
- name: 'name'

mmv1/provider/terraform_tgc_next.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,15 +377,15 @@ func (tgc TerraformGoogleConversionNext) addTestsFromHandwrittenTests(object *ap
377377
}
378378

379379
matches := testRegex.FindAllSubmatch(data, -1)
380-
tests := make([]resource.TGCTest, len(matches))
381-
for i, match := range matches {
380+
tests := make([]resource.TGCTest, 0)
381+
for _, match := range matches {
382382
if len(match) == 2 {
383383
if _, ok := testNamesInYAML[string(match[1])]; ok {
384384
continue
385385
}
386-
tests[i] = resource.TGCTest{
386+
tests = append(tests, resource.TGCTest{
387387
Name: string(match[1]),
388-
}
388+
})
389389
}
390390
}
391391

mmv1/third_party/terraform/services/container/resource_container_cluster.go.tmpl

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5966,13 +5966,17 @@ func expandClusterAutoscaling(configured interface{}, d *schema.ResourceData) *c
59665966
Enabled: defaultCCEnabled.(bool),
59675967
}
59685968
}
5969+
var defaults *container.AutoprovisioningNodePoolDefaults
5970+
if shouldInclude(d, "cluster_autoscaling.0.auto_provisioning_defaults") {
5971+
defaults = expandAutoProvisioningDefaults(config["auto_provisioning_defaults"], d)
5972+
}
59695973
return &container.ClusterAutoscaling{
5970-
EnableNodeAutoprovisioning: config["enabled"].(bool),
5971-
ResourceLimits: resourceLimits,
5972-
DefaultComputeClassConfig: defaultCCConfig,
5973-
AutoscalingProfile: config["autoscaling_profile"].(string),
5974-
AutoprovisioningNodePoolDefaults: expandAutoProvisioningDefaults(config["auto_provisioning_defaults"], d),
5975-
AutoprovisioningLocations: tpgresource.ConvertStringArr(config["auto_provisioning_locations"].([]interface{})),
5974+
EnableNodeAutoprovisioning: config["enabled"].(bool),
5975+
ResourceLimits: resourceLimits,
5976+
DefaultComputeClassConfig: defaultCCConfig,
5977+
AutoscalingProfile: config["autoscaling_profile"].(string),
5978+
AutoprovisioningNodePoolDefaults: defaults,
5979+
AutoprovisioningLocations: tpgresource.ConvertStringArr(config["auto_provisioning_locations"].([]interface{})),
59765980
}
59775981
}
59785982

@@ -5983,15 +5987,23 @@ func expandAutoProvisioningDefaults(configured interface{}, d *schema.ResourceDa
59835987
}
59845988
config := l[0].(map[string]interface{})
59855989

5990+
var management *container.NodeManagement
5991+
if shouldInclude(d, "cluster_autoscaling.0.auto_provisioning_defaults.0.management") {
5992+
management = expandManagement(config["management"])
5993+
}
5994+
var upgradeSettings *container.UpgradeSettings
5995+
if shouldInclude(d, "cluster_autoscaling.0.auto_provisioning_defaults.0.upgrade_settings") {
5996+
upgradeSettings = expandUpgradeSettings(config["upgrade_settings"], d)
5997+
}
59865998
npd := &container.AutoprovisioningNodePoolDefaults{
5987-
OauthScopes: tpgresource.ConvertStringArr(config["oauth_scopes"].([]interface{})),
5988-
ServiceAccount: config["service_account"].(string),
5989-
DiskSizeGb: int64(config["disk_size"].(int)),
5990-
DiskType: config["disk_type"].(string),
5991-
ImageType: config["image_type"].(string),
5992-
BootDiskKmsKey: config["boot_disk_kms_key"].(string),
5993-
Management: expandManagement(config["management"]),
5994-
UpgradeSettings: expandUpgradeSettings(config["upgrade_settings"]),
5999+
OauthScopes: tpgresource.ConvertStringArr(config["oauth_scopes"].([]interface{})),
6000+
ServiceAccount: config["service_account"].(string),
6001+
DiskSizeGb: int64(config["disk_size"].(int)),
6002+
DiskType: config["disk_type"].(string),
6003+
ImageType: config["image_type"].(string),
6004+
BootDiskKmsKey: config["boot_disk_kms_key"].(string),
6005+
Management: management,
6006+
UpgradeSettings: upgradeSettings,
59956007
}
59966008

59976009
if v, ok := config["shielded_instance_config"]; ok && len(v.([]interface{})) > 0 {
@@ -6012,18 +6024,22 @@ func expandAutoProvisioningDefaults(configured interface{}, d *schema.ResourceDa
60126024
return npd
60136025
}
60146026

6015-
func expandUpgradeSettings(configured interface{}) *container.UpgradeSettings {
6027+
func expandUpgradeSettings(configured interface{}, d *schema.ResourceData) *container.UpgradeSettings {
60166028
l, ok := configured.([]interface{})
60176029
if !ok || l == nil || len(l) == 0 || l[0] == nil {
60186030
return &container.UpgradeSettings{}
60196031
}
60206032
config := l[0].(map[string]interface{})
60216033

6034+
var blueGreenSettings *container.BlueGreenSettings
6035+
if shouldInclude(d, "cluster_autoscaling.0.auto_provisioning_defaults.0.upgrade_settings.0.blue_green_settings") {
6036+
blueGreenSettings = expandBlueGreenSettings(config["blue_green_settings"])
6037+
}
60226038
upgradeSettings := &container.UpgradeSettings{
60236039
MaxSurge: int64(config["max_surge"].(int)),
60246040
MaxUnavailable: int64(config["max_unavailable"].(int)),
60256041
Strategy: config["strategy"].(string),
6026-
BlueGreenSettings: expandBlueGreenSettings(config["blue_green_settings"]),
6042+
BlueGreenSettings: blueGreenSettings,
60276043
}
60286044

60296045
return upgradeSettings
@@ -6091,6 +6107,10 @@ func expandUpgradeOptions(configured interface{}) *container.AutoUpgradeOptions
60916107
return upgradeOptions
60926108
}
60936109

6110+
func shouldInclude(d *schema.ResourceData, key string) bool {
6111+
return d.IsNewResource() || d.HasChange(key)
6112+
}
6113+
60946114
func expandAuthenticatorGroupsConfig(configured interface{}) *container.AuthenticatorGroupsConfig {
60956115
l := configured.([]interface{})
60966116
if len(l) == 0 {

mmv1/third_party/terraform/services/container/resource_container_cluster_test.go.tmpl

Lines changed: 102 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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(`
43794437
resource "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

Comments
 (0)