Skip to content

Commit

Permalink
allow updating google_container_cluster.logging_service (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
danawillow committed Aug 18, 2017
1 parent 908ede0 commit 07cf281
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 4 deletions.
31 changes: 27 additions & 4 deletions google/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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)
Expand Down
50 changes: 50 additions & 0 deletions google/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 07cf281

Please sign in to comment.