diff --git a/google/resource_container_cluster.go b/google/resource_container_cluster.go index e53cb65b178..d38094140e5 100644 --- a/google/resource_container_cluster.go +++ b/google/resource_container_cluster.go @@ -694,6 +694,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, + }, + }, + }, + }, + "enable_intranode_visibility": { Type: schema.TypeBool, Optional: true, @@ -875,6 +889,10 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er cluster.PrivateClusterConfig = expandPrivateClusterConfig(v) } + if v, ok := d.GetOk("vertical_pod_autoscaling"); ok { + cluster.VerticalPodAutoscaling = expandVerticalPodAutoscaling(v) + } + req := &containerBeta.CreateClusterRequest{ Cluster: cluster, } @@ -1039,6 +1057,10 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro return err } + if err := d.Set("vertical_pod_autoscaling", flattenVerticalPodAutoscaling(cluster.VerticalPodAutoscaling)); err != nil { + return err + } + d.Set("resource_labels", cluster.ResourceLabels) return nil @@ -1451,6 +1473,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("resource_labels") { resourceLabels := d.Get("resource_labels").(map[string]interface{}) req := &containerBeta.SetLabelsRequest{ @@ -1889,6 +1931,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 expandPodSecurityPolicyConfig(configured interface{}) *containerBeta.PodSecurityPolicyConfig { // Removing lists is hard - the element count (#) will have a diff from nil -> computed // If we set this to empty on Read, it will be stable. @@ -1992,6 +2045,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 flattenIPAllocationPolicy(c *containerBeta.Cluster, d *schema.ResourceData, config *Config) []map[string]interface{} { // If IP aliasing isn't enabled, none of the values in this block can be set. if c == nil || c.IpAllocationPolicy == nil || !c.IpAllocationPolicy.UseIpAliases { diff --git a/google/resource_container_cluster_test.go b/google/resource_container_cluster_test.go index 56f4398eb6b..dba0ef7577d 100644 --- a/google/resource_container_cluster_test.go +++ b/google/resource_container_cluster_test.go @@ -1273,6 +1273,10 @@ resource "google_container_cluster" "primary" { created-by = "terraform" } + vertical_pod_autoscaling { + enabled = true + } + } `, name) } @@ -1302,6 +1306,10 @@ resource "google_container_cluster" "primary" { new-label = "update" } + vertical_pod_autoscaling { + enabled = true + } + } `, name) }