diff --git a/third_party/terraform/resources/resource_container_cluster.go.erb b/third_party/terraform/resources/resource_container_cluster.go.erb index 805b4940b98c..5ca168e264a7 100644 --- a/third_party/terraform/resources/resource_container_cluster.go.erb +++ b/third_party/terraform/resources/resource_container_cluster.go.erb @@ -395,6 +395,13 @@ func resourceContainerCluster() *schema.Resource { Optional: true, Default: "default", }, + <% unless version == 'ga' -%> + "min_cpu_platform": { + Type: schema.TypeString, + Optional: true, + DiffSuppressFunc: emptyOrDefaultStringSuppress("automatic"), + }, + <% end -%> }, }, }, @@ -2467,10 +2474,20 @@ func expandAutoProvisioningDefaults(configured interface{}, d *schema.ResourceDa } config := l[0].(map[string]interface{}) - return &containerBeta.AutoprovisioningNodePoolDefaults{ + npd := &containerBeta.AutoprovisioningNodePoolDefaults{ OauthScopes: convertStringArr(config["oauth_scopes"].([]interface{})), ServiceAccount: config["service_account"].(string), } + + <% unless version == 'ga' -%> + cpu := config["min_cpu_platform"].(string) + // the only way to unset the field is to pass "automatic" as its value + if cpu == "" { + cpu = "automatic" + } + npd.MinCpuPlatform = cpu + <% end -%> + return npd } func expandAuthenticatorGroupsConfig(configured interface{}) *containerBeta.AuthenticatorGroupsConfig { @@ -2958,6 +2975,9 @@ func flattenAutoProvisioningDefaults(a *containerBeta.AutoprovisioningNodePoolDe r := make(map[string]interface{}) r["oauth_scopes"] = a.OauthScopes r["service_account"] = a.ServiceAccount + <% unless version == 'ga' -%> + r["min_cpu_platform"] = a.MinCpuPlatform + <% end -%> return []map[string]interface{}{r} } diff --git a/third_party/terraform/tests/resource_container_cluster_test.go.erb b/third_party/terraform/tests/resource_container_cluster_test.go.erb index 6088bf339b02..45d2d5c7566c 100644 --- a/third_party/terraform/tests/resource_container_cluster_test.go.erb +++ b/third_party/terraform/tests/resource_container_cluster_test.go.erb @@ -1414,6 +1414,41 @@ func TestAccContainerCluster_withShieldedNodes(t *testing.T) { } <% unless version == 'ga' -%> +// consider merging this test with TestAccContainerCluster_nodeAutoprovisioningDefaults +// once the feature is GA +func TestAccContainerCluster_nodeAutoprovisioningDefaultsMinCpuPlatform(t *testing.T) { + t.Parallel() + + clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10)) + includeMinCpuPlatform := true + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckContainerClusterDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccContainerCluster_autoprovisioningDefaultsMinCpuPlatform(clusterName, includeMinCpuPlatform), + }, + { + ResourceName: "google_container_cluster.with_autoprovisioning", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"min_master_version"}, + }, + { + Config: testAccContainerCluster_autoprovisioningDefaultsMinCpuPlatform(clusterName, !includeMinCpuPlatform), + }, + { + ResourceName: "google_container_cluster.with_autoprovisioning", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"min_master_version"}, + }, + }, + }) +} + func TestAccContainerCluster_withAutoscalingProfile(t *testing.T) { t.Parallel() clusterName := fmt.Sprintf("cluster-test-%s", randString(t, 10)) @@ -3058,6 +3093,45 @@ if monitoringWrite { return config } +<% unless version == 'ga' -%> +func testAccContainerCluster_autoprovisioningDefaultsMinCpuPlatform(cluster string, includeMinCpuPlatform bool) string { + minCpuPlatformCfg := "" + if includeMinCpuPlatform { + minCpuPlatformCfg = `min_cpu_platform = "Intel Haswell"` + } + + return fmt.Sprintf(` +data "google_container_engine_versions" "central1a" { + location = "us-central1-a" +} + +resource "google_container_cluster" "with_autoprovisioning" { + name = "%s" + location = "us-central1-a" + initial_node_count = 1 + + min_master_version = data.google_container_engine_versions.central1a.latest_master_version + + cluster_autoscaling { + enabled = true + + resource_limits { + resource_type = "cpu" + maximum = 2 + } + resource_limits { + resource_type = "memory" + maximum = 2048 + } + + auto_provisioning_defaults { + %s + } + } +}`, cluster, minCpuPlatformCfg) +} +<% end -%> + func testAccContainerCluster_withNodePoolAutoscaling(cluster, np string) string { return fmt.Sprintf(` resource "google_container_cluster" "with_node_pool" { diff --git a/third_party/terraform/website/docs/r/container_cluster.html.markdown b/third_party/terraform/website/docs/r/container_cluster.html.markdown index d9ffb4277f20..147f2581fca2 100644 --- a/third_party/terraform/website/docs/r/container_cluster.html.markdown +++ b/third_party/terraform/website/docs/r/container_cluster.html.markdown @@ -140,7 +140,7 @@ in this cluster in CIDR notation (e.g. `10.96.0.0/14`). Leave blank to have one automatically chosen or specify a `/14` block in `10.0.0.0/8`. This field will only work for routes-based clusters, where `ip_allocation_policy` is not defined. -* `cluster_autoscaling` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) +* `cluster_autoscaling` - (Optional) Per-cluster configuration of Node Auto-Provisioning with Cluster Autoscaler to automatically adjust the size of the cluster and create/delete node pools based on the current needs of the cluster's workload. See the @@ -408,6 +408,11 @@ for a list of types. The `auto_provisioning_defaults` block supports: +* `min_cpu_platform` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) +Minimum CPU platform to be used for NAP created node pools. The instance may be scheduled on the +specified or newer CPU platform. Applicable values are the friendly names of CPU platforms, such +as "Intel Haswell" or "Intel Sandy Bridge". + * `oauth_scopes` - (Optional) Scopes that are used by NAP when creating node pools. -> `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`.