Skip to content

Commit 049202b

Browse files
add min_cpu_platform to google_container_cluster.cluster_autoscaling.auto_provisioning_defaults (#3383) (#2086)
Signed-off-by: Modular Magician <[email protected]>
1 parent e30b174 commit 049202b

File tree

4 files changed

+96
-2
lines changed

4 files changed

+96
-2
lines changed

.changelog/3383.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
* container: added `min_cpu_platform` to google_container_cluster.cluster_autoscaling.auto_provisioning_defaults [beta-only]
3+
```

google-beta/resource_container_cluster.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,11 @@ func resourceContainerCluster() *schema.Resource {
390390
Optional: true,
391391
Default: "default",
392392
},
393+
"min_cpu_platform": {
394+
Type: schema.TypeString,
395+
Optional: true,
396+
DiffSuppressFunc: emptyOrDefaultStringSuppress("automatic"),
397+
},
393398
},
394399
},
395400
},
@@ -2424,10 +2429,18 @@ func expandAutoProvisioningDefaults(configured interface{}, d *schema.ResourceDa
24242429
}
24252430
config := l[0].(map[string]interface{})
24262431

2427-
return &containerBeta.AutoprovisioningNodePoolDefaults{
2432+
npd := &containerBeta.AutoprovisioningNodePoolDefaults{
24282433
OauthScopes: convertStringArr(config["oauth_scopes"].([]interface{})),
24292434
ServiceAccount: config["service_account"].(string),
24302435
}
2436+
2437+
cpu := config["min_cpu_platform"].(string)
2438+
// the only way to unset the field is to pass "automatic" as its value
2439+
if cpu == "" {
2440+
cpu = "automatic"
2441+
}
2442+
npd.MinCpuPlatform = cpu
2443+
return npd
24312444
}
24322445

24332446
func expandAuthenticatorGroupsConfig(configured interface{}) *containerBeta.AuthenticatorGroupsConfig {
@@ -2901,6 +2914,7 @@ func flattenAutoProvisioningDefaults(a *containerBeta.AutoprovisioningNodePoolDe
29012914
r := make(map[string]interface{})
29022915
r["oauth_scopes"] = a.OauthScopes
29032916
r["service_account"] = a.ServiceAccount
2917+
r["min_cpu_platform"] = a.MinCpuPlatform
29042918

29052919
return []map[string]interface{}{r}
29062920
}

google-beta/resource_container_cluster_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,41 @@ func TestAccContainerCluster_withShieldedNodes(t *testing.T) {
14051405
})
14061406
}
14071407

1408+
// consider merging this test with TestAccContainerCluster_nodeAutoprovisioningDefaults
1409+
// once the feature is GA
1410+
func TestAccContainerCluster_nodeAutoprovisioningDefaultsMinCpuPlatform(t *testing.T) {
1411+
t.Parallel()
1412+
1413+
clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
1414+
includeMinCpuPlatform := true
1415+
1416+
vcrTest(t, resource.TestCase{
1417+
PreCheck: func() { testAccPreCheck(t) },
1418+
Providers: testAccProviders,
1419+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
1420+
Steps: []resource.TestStep{
1421+
{
1422+
Config: testAccContainerCluster_autoprovisioningDefaultsMinCpuPlatform(clusterName, includeMinCpuPlatform),
1423+
},
1424+
{
1425+
ResourceName: "google_container_cluster.with_autoprovisioning",
1426+
ImportState: true,
1427+
ImportStateVerify: true,
1428+
ImportStateVerifyIgnore: []string{"min_master_version"},
1429+
},
1430+
{
1431+
Config: testAccContainerCluster_autoprovisioningDefaultsMinCpuPlatform(clusterName, !includeMinCpuPlatform),
1432+
},
1433+
{
1434+
ResourceName: "google_container_cluster.with_autoprovisioning",
1435+
ImportState: true,
1436+
ImportStateVerify: true,
1437+
ImportStateVerifyIgnore: []string{"min_master_version"},
1438+
},
1439+
},
1440+
})
1441+
}
1442+
14081443
func TestAccContainerCluster_withAutoscalingProfile(t *testing.T) {
14091444
t.Parallel()
14101445
clusterName := fmt.Sprintf("cluster-test-%s", randString(t, 10))
@@ -3025,6 +3060,43 @@ resource "google_container_cluster" "with_autoprovisioning" {
30253060
return config
30263061
}
30273062

3063+
func testAccContainerCluster_autoprovisioningDefaultsMinCpuPlatform(cluster string, includeMinCpuPlatform bool) string {
3064+
minCpuPlatformCfg := ""
3065+
if includeMinCpuPlatform {
3066+
minCpuPlatformCfg = `min_cpu_platform = "Intel Haswell"`
3067+
}
3068+
3069+
return fmt.Sprintf(`
3070+
data "google_container_engine_versions" "central1a" {
3071+
location = "us-central1-a"
3072+
}
3073+
3074+
resource "google_container_cluster" "with_autoprovisioning" {
3075+
name = "%s"
3076+
location = "us-central1-a"
3077+
initial_node_count = 1
3078+
3079+
min_master_version = data.google_container_engine_versions.central1a.latest_master_version
3080+
3081+
cluster_autoscaling {
3082+
enabled = true
3083+
3084+
resource_limits {
3085+
resource_type = "cpu"
3086+
maximum = 2
3087+
}
3088+
resource_limits {
3089+
resource_type = "memory"
3090+
maximum = 2048
3091+
}
3092+
3093+
auto_provisioning_defaults {
3094+
%s
3095+
}
3096+
}
3097+
}`, cluster, minCpuPlatformCfg)
3098+
}
3099+
30283100
func testAccContainerCluster_withNodePoolAutoscaling(cluster, np string) string {
30293101
return fmt.Sprintf(`
30303102
resource "google_container_cluster" "with_node_pool" {

website/docs/r/container_cluster.html.markdown

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ in this cluster in CIDR notation (e.g. `10.96.0.0/14`). Leave blank to have one
140140
automatically chosen or specify a `/14` block in `10.0.0.0/8`. This field will
141141
only work for routes-based clusters, where `ip_allocation_policy` is not defined.
142142

143-
* `cluster_autoscaling` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
143+
* `cluster_autoscaling` - (Optional)
144144
Per-cluster configuration of Node Auto-Provisioning with Cluster Autoscaler to
145145
automatically adjust the size of the cluster and create/delete node pools based
146146
on the current needs of the cluster's workload. See the
@@ -408,6 +408,11 @@ for a list of types.
408408

409409
The `auto_provisioning_defaults` block supports:
410410

411+
* `min_cpu_platform` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html))
412+
Minimum CPU platform to be used for NAP created node pools. The instance may be scheduled on the
413+
specified or newer CPU platform. Applicable values are the friendly names of CPU platforms, such
414+
as "Intel Haswell" or "Intel Sandy Bridge".
415+
411416
* `oauth_scopes` - (Optional) Scopes that are used by NAP when creating node pools.
412417

413418
-> `monitoring.write` is always enabled regardless of user input. `monitoring` and `logging.write` may also be enabled depending on the values for `monitoring_service` and `logging_service`.

0 commit comments

Comments
 (0)