Skip to content

Commit

Permalink
add min_cpu_platform to google_container_cluster.cluster_autoscaling.…
Browse files Browse the repository at this point in the history
…auto_provisioning_defaults (#3383) (#2086)

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored May 19, 2020
1 parent e30b174 commit 049202b
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/3383.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
* container: added `min_cpu_platform` to google_container_cluster.cluster_autoscaling.auto_provisioning_defaults [beta-only]
```
16 changes: 15 additions & 1 deletion google-beta/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ func resourceContainerCluster() *schema.Resource {
Optional: true,
Default: "default",
},
"min_cpu_platform": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: emptyOrDefaultStringSuppress("automatic"),
},
},
},
},
Expand Down Expand Up @@ -2424,10 +2429,18 @@ 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),
}

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
return npd
}

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

return []map[string]interface{}{r}
}
Expand Down
72 changes: 72 additions & 0 deletions google-beta/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,41 @@ func TestAccContainerCluster_withShieldedNodes(t *testing.T) {
})
}

// 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))
Expand Down Expand Up @@ -3025,6 +3060,43 @@ resource "google_container_cluster" "with_autoprovisioning" {
return config
}

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)
}

func testAccContainerCluster_withNodePoolAutoscaling(cluster, np string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_node_pool" {
Expand Down
7 changes: 6 additions & 1 deletion website/docs/r/container_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`.
Expand Down

0 comments on commit 049202b

Please sign in to comment.