diff --git a/google/resource_container_cluster.go b/google/resource_container_cluster.go index 1d88605b8a5..282470ac781 100644 --- a/google/resource_container_cluster.go +++ b/google/resource_container_cluster.go @@ -157,10 +157,10 @@ func resourceContainerCluster() *schema.Resource { }, "logging_service": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validation.StringInSlice([]string{"logging.googleapis.com", "none"}, false), }, "monitoring_service": { @@ -649,6 +649,29 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er d.SetPartial("node_pool") } + if d.HasChange("logging_service") { + logging := d.Get("logging_service").(string) + + req := &container.SetLoggingServiceRequest{ + LoggingService: logging, + } + op, err := config.clientContainer.Projects.Zones.Clusters.Logging( + project, zoneName, clusterName, req).Do() + if err != nil { + return err + } + + // Wait until it's updated + waitErr := containerOperationWait(config, op, project, zoneName, "updating GKE logging service", timeoutInMinutes, 2) + if waitErr != nil { + return waitErr + } + + log.Printf("[INFO] GKE cluster %s: logging service has been updated to %s", d.Id(), + logging) + d.SetPartial("logging_service") + } + d.Partial(false) return resourceContainerClusterRead(d, meta) diff --git a/google/resource_container_cluster_test.go b/google/resource_container_cluster_test.go index de671462bc6..d7df8d46f88 100644 --- a/google/resource_container_cluster_test.go +++ b/google/resource_container_cluster_test.go @@ -236,6 +236,34 @@ func TestAccContainerCluster_backend(t *testing.T) { }) } +func TestAccContainerCluster_withLogging(t *testing.T) { + 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_withLogging(clusterName), + Check: resource.ComposeTestCheckFunc( + testAccCheckContainerCluster( + "google_container_cluster.with_logging"), + resource.TestCheckResourceAttr("google_container_cluster.with_logging", "logging_service", "logging.googleapis.com"), + ), + }, + { + Config: testAccContainerCluster_updateLogging(clusterName), + Check: resource.ComposeTestCheckFunc( + testAccCheckContainerCluster( + "google_container_cluster.with_logging"), + resource.TestCheckResourceAttr("google_container_cluster.with_logging", "logging_service", "none"), + ), + }, + }, + }) +} + func TestAccContainerCluster_withNodePoolBasic(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -838,6 +866,28 @@ resource "google_container_cluster" "primary" { } `, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10)) +func testAccContainerCluster_withLogging(clusterName string) string { + return fmt.Sprintf(` +resource "google_container_cluster" "with_logging" { + name = "cluster-test-%s" + zone = "us-central1-a" + initial_node_count = 1 + + logging_service = "logging.googleapis.com" +}`, clusterName) +} + +func testAccContainerCluster_updateLogging(clusterName string) string { + return fmt.Sprintf(` +resource "google_container_cluster" "with_logging" { + name = "cluster-test-%s" + zone = "us-central1-a" + initial_node_count = 1 + + logging_service = "none" +}`, clusterName) +} + var testAccContainerCluster_withNodePoolBasic = fmt.Sprintf(` resource "google_container_cluster" "with_node_pool" { name = "tf-cluster-nodepool-test-%s"