From 62eb5ceedf9b18bf95ba09df9fef945483a8f6f4 Mon Sep 17 00:00:00 2001 From: Dana Hoffman Date: Fri, 20 Oct 2017 09:46:21 -0700 Subject: [PATCH] Allow updating `google_container_cluster.monitoring_service` (#598) --- google/resource_container_cluster.go | 26 +++++++++++- google/resource_container_cluster_test.go | 52 +++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/google/resource_container_cluster.go b/google/resource_container_cluster.go index 17be40e8..b0b953b3 100644 --- a/google/resource_container_cluster.go +++ b/google/resource_container_cluster.go @@ -173,7 +173,6 @@ func resourceContainerCluster() *schema.Resource { Type: schema.TypeString, Optional: true, Computed: true, - ForceNew: true, }, "network": { @@ -647,6 +646,31 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er d.SetPartial("enable_legacy_abac") } + if d.HasChange("monitoring_service") { + desiredMonitoringService := d.Get("monitoring_service").(string) + + req := &container.UpdateClusterRequest{ + Update: &container.ClusterUpdate{ + DesiredMonitoringService: desiredMonitoringService, + }, + } + op, err := config.clientContainer.Projects.Zones.Clusters.Update( + project, zoneName, clusterName, req).Do() + if err != nil { + return err + } + + // Wait until it's updated + waitErr := containerOperationWait(config, op, project, zoneName, "updating GKE cluster monitoring service", timeoutInMinutes, 2) + if waitErr != nil { + return waitErr + } + log.Printf("[INFO] Monitoring service for GKE cluster %s has been updated to %s", d.Id(), + desiredMonitoringService) + + d.SetPartial("monitoring_service") + } + if n, ok := d.GetOk("node_pool.#"); ok { for i := 0; i < n.(int); i++ { if err := nodePoolUpdate(d, meta, clusterName, fmt.Sprintf("node_pool.%d.", i), timeoutInMinutes); err != nil { diff --git a/google/resource_container_cluster_test.go b/google/resource_container_cluster_test.go index 594a118a..c1b592f3 100644 --- a/google/resource_container_cluster_test.go +++ b/google/resource_container_cluster_test.go @@ -306,6 +306,36 @@ func TestAccContainerCluster_withLogging(t *testing.T) { }) } +func TestAccContainerCluster_withMonitoring(t *testing.T) { + t.Parallel() + + clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckContainerClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccContainerCluster_withMonitoring(clusterName), + Check: resource.ComposeTestCheckFunc( + testAccCheckContainerCluster( + "google_container_cluster.with_monitoring"), + resource.TestCheckResourceAttr("google_container_cluster.with_monitoring", "monitoring_service", "monitoring.googleapis.com"), + ), + }, + { + Config: testAccContainerCluster_updateMonitoring(clusterName), + Check: resource.ComposeTestCheckFunc( + testAccCheckContainerCluster( + "google_container_cluster.with_monitoring"), + resource.TestCheckResourceAttr("google_container_cluster.with_monitoring", "monitoring_service", "none"), + ), + }, + }, + }) +} + func TestAccContainerCluster_withNodePoolBasic(t *testing.T) { t.Parallel() @@ -1065,6 +1095,28 @@ resource "google_container_cluster" "with_logging" { }`, clusterName) } +func testAccContainerCluster_withMonitoring(clusterName string) string { + return fmt.Sprintf(` +resource "google_container_cluster" "with_monitoring" { + name = "cluster-test-%s" + zone = "us-central1-a" + initial_node_count = 1 + + monitoring_service = "monitoring.googleapis.com" +}`, clusterName) +} + +func testAccContainerCluster_updateMonitoring(clusterName string) string { + return fmt.Sprintf(` +resource "google_container_cluster" "with_monitoring" { + name = "cluster-test-%s" + zone = "us-central1-a" + initial_node_count = 1 + + monitoring_service = "none" +}`, clusterName) +} + func testAccContainerCluster_withNodePoolBasic(cluster, nodePool string) string { return fmt.Sprintf(` resource "google_container_cluster" "with_node_pool" {