From 5172834a3fd57ef0d705e71006847fbe61f5955f Mon Sep 17 00:00:00 2001 From: Sam Levenick Date: Mon, 2 Dec 2019 20:59:37 +0000 Subject: [PATCH] Move vertical_pod_autoscaling to GA in container cluster Signed-off-by: Modular Magician --- google-beta/resource_container_cluster.go | 119 +++++++++--------- .../resource_container_cluster_test.go | 12 +- 2 files changed, 66 insertions(+), 65 deletions(-) diff --git a/google-beta/resource_container_cluster.go b/google-beta/resource_container_cluster.go index 8b88389ea0..ad8dab9acc 100644 --- a/google-beta/resource_container_cluster.go +++ b/google-beta/resource_container_cluster.go @@ -796,6 +796,20 @@ func resourceContainerCluster() *schema.Resource { Computed: true, }, + "vertical_pod_autoscaling": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "enabled": { + Type: schema.TypeBool, + Required: true, + }, + }, + }, + }, + "release_channel": { Type: schema.TypeList, ForceNew: true, @@ -815,20 +829,6 @@ func resourceContainerCluster() *schema.Resource { }, }, - "vertical_pod_autoscaling": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "enabled": { - Type: schema.TypeBool, - Required: true, - }, - }, - }, - }, - "workload_identity_config": { Type: schema.TypeList, MaxItems: 1, @@ -1093,14 +1093,14 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er cluster.PrivateClusterConfig = expandPrivateClusterConfig(v) } - if v, ok := d.GetOk("database_encryption"); ok { - cluster.DatabaseEncryption = expandDatabaseEncryption(v) - } - if v, ok := d.GetOk("vertical_pod_autoscaling"); ok { cluster.VerticalPodAutoscaling = expandVerticalPodAutoscaling(v) } + if v, ok := d.GetOk("database_encryption"); ok { + cluster.DatabaseEncryption = expandDatabaseEncryption(v) + } + if v, ok := d.GetOk("workload_identity_config"); ok { cluster.WorkloadIdentityConfig = expandWorkloadIdentityConfig(v) } @@ -1792,6 +1792,26 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er d.SetPartial("master_auth") } + if d.HasChange("vertical_pod_autoscaling") { + if ac, ok := d.GetOk("vertical_pod_autoscaling"); ok { + req := &containerBeta.UpdateClusterRequest{ + Update: &containerBeta.ClusterUpdate{ + DesiredVerticalPodAutoscaling: expandVerticalPodAutoscaling(ac), + }, + } + + updateF := updateFunc(req, "updating GKE cluster vertical pod autoscaling") + // Call update serially. + if err := lockedCall(lockKey, updateF); err != nil { + return err + } + + log.Printf("[INFO] GKE cluster %s vertical pod autoscaling has been updated", d.Id()) + + d.SetPartial("vertical_pod_autoscaling") + } + } + if d.HasChange("pod_security_policy_config") { c := d.Get("pod_security_policy_config") req := &containerBeta.UpdateClusterRequest{ @@ -1817,26 +1837,6 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er d.SetPartial("pod_security_policy_config") } - if d.HasChange("vertical_pod_autoscaling") { - if ac, ok := d.GetOk("vertical_pod_autoscaling"); ok { - req := &containerBeta.UpdateClusterRequest{ - Update: &containerBeta.ClusterUpdate{ - DesiredVerticalPodAutoscaling: expandVerticalPodAutoscaling(ac), - }, - } - - updateF := updateFunc(req, "updating GKE cluster vertical pod autoscaling") - // Call update serially. - if err := lockedCall(lockKey, updateF); err != nil { - return err - } - - log.Printf("[INFO] GKE cluster %s vertical pod autoscaling has been updated", d.Id()) - - d.SetPartial("vertical_pod_autoscaling") - } - } - if d.HasChange("workload_identity_config") { // Because GKE uses a non-RESTful update function, when removing the // feature you need to specify a fairly full request body or it fails: @@ -2361,6 +2361,17 @@ func expandPrivateClusterConfig(configured interface{}) *containerBeta.PrivateCl } } +func expandVerticalPodAutoscaling(configured interface{}) *containerBeta.VerticalPodAutoscaling { + l := configured.([]interface{}) + if len(l) == 0 { + return nil + } + config := l[0].(map[string]interface{}) + return &containerBeta.VerticalPodAutoscaling{ + Enabled: config["enabled"].(bool), + } +} + func expandReleaseChannel(configured interface{}) *containerBeta.ReleaseChannel { l := configured.([]interface{}) if len(l) == 0 || l[0] == nil { @@ -2384,17 +2395,6 @@ func expandDatabaseEncryption(configured interface{}) *containerBeta.DatabaseEnc } } -func expandVerticalPodAutoscaling(configured interface{}) *containerBeta.VerticalPodAutoscaling { - l := configured.([]interface{}) - if len(l) == 0 { - return nil - } - config := l[0].(map[string]interface{}) - return &containerBeta.VerticalPodAutoscaling{ - Enabled: config["enabled"].(bool), - } -} - func expandWorkloadIdentityConfig(configured interface{}) *containerBeta.WorkloadIdentityConfig { l := configured.([]interface{}) if len(l) == 0 || l[0] == nil { @@ -2558,6 +2558,17 @@ func flattenPrivateClusterConfig(c *containerBeta.PrivateClusterConfig) []map[st } } +func flattenVerticalPodAutoscaling(c *containerBeta.VerticalPodAutoscaling) []map[string]interface{} { + if c == nil { + return nil + } + return []map[string]interface{}{ + { + "enabled": c.Enabled, + }, + } +} + func flattenReleaseChannel(c *containerBeta.ReleaseChannel) []map[string]interface{} { result := []map[string]interface{}{} if c != nil { @@ -2573,16 +2584,6 @@ func flattenReleaseChannel(c *containerBeta.ReleaseChannel) []map[string]interfa return result } -func flattenVerticalPodAutoscaling(c *containerBeta.VerticalPodAutoscaling) []map[string]interface{} { - if c == nil { - return nil - } - return []map[string]interface{}{ - { - "enabled": c.Enabled, - }, - } -} func flattenWorkloadIdentityConfig(c *containerBeta.WorkloadIdentityConfig) []map[string]interface{} { if c == nil { return nil diff --git a/google-beta/resource_container_cluster_test.go b/google-beta/resource_container_cluster_test.go index 7d981ca94f..41f0440056 100644 --- a/google-beta/resource_container_cluster_test.go +++ b/google-beta/resource_container_cluster_test.go @@ -1712,12 +1712,12 @@ resource "google_container_cluster" "primary" { created-by = "terraform" } - enable_intranode_visibility = true - enable_binary_authorization = true - vertical_pod_autoscaling { enabled = true } + + enable_intranode_visibility = true + enable_binary_authorization = true } `, name) } @@ -1747,12 +1747,12 @@ resource "google_container_cluster" "primary" { new-label = "update" } - enable_intranode_visibility = true - enable_binary_authorization = true - vertical_pod_autoscaling { enabled = true } + + enable_intranode_visibility = true + enable_binary_authorization = true } `, name) }