Skip to content

Commit 3901e22

Browse files
authored
allow updating google_container_cluster.logging_service (hashicorp#343)
1 parent c574e21 commit 3901e22

File tree

2 files changed

+77
-4
lines changed

2 files changed

+77
-4
lines changed

google/resource_container_cluster.go

+27-4
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ func resourceContainerCluster() *schema.Resource {
157157
},
158158

159159
"logging_service": {
160-
Type: schema.TypeString,
161-
Optional: true,
162-
Computed: true,
163-
ForceNew: true,
160+
Type: schema.TypeString,
161+
Optional: true,
162+
Computed: true,
163+
ValidateFunc: validation.StringInSlice([]string{"logging.googleapis.com", "none"}, false),
164164
},
165165

166166
"monitoring_service": {
@@ -649,6 +649,29 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
649649
d.SetPartial("node_pool")
650650
}
651651

652+
if d.HasChange("logging_service") {
653+
logging := d.Get("logging_service").(string)
654+
655+
req := &container.SetLoggingServiceRequest{
656+
LoggingService: logging,
657+
}
658+
op, err := config.clientContainer.Projects.Zones.Clusters.Logging(
659+
project, zoneName, clusterName, req).Do()
660+
if err != nil {
661+
return err
662+
}
663+
664+
// Wait until it's updated
665+
waitErr := containerOperationWait(config, op, project, zoneName, "updating GKE logging service", timeoutInMinutes, 2)
666+
if waitErr != nil {
667+
return waitErr
668+
}
669+
670+
log.Printf("[INFO] GKE cluster %s: logging service has been updated to %s", d.Id(),
671+
logging)
672+
d.SetPartial("logging_service")
673+
}
674+
652675
d.Partial(false)
653676

654677
return resourceContainerClusterRead(d, meta)

google/resource_container_cluster_test.go

+50
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,34 @@ func TestAccContainerCluster_backend(t *testing.T) {
236236
})
237237
}
238238

239+
func TestAccContainerCluster_withLogging(t *testing.T) {
240+
clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10))
241+
242+
resource.Test(t, resource.TestCase{
243+
PreCheck: func() { testAccPreCheck(t) },
244+
Providers: testAccProviders,
245+
CheckDestroy: testAccCheckContainerClusterDestroy,
246+
Steps: []resource.TestStep{
247+
{
248+
Config: testAccContainerCluster_withLogging(clusterName),
249+
Check: resource.ComposeTestCheckFunc(
250+
testAccCheckContainerCluster(
251+
"google_container_cluster.with_logging"),
252+
resource.TestCheckResourceAttr("google_container_cluster.with_logging", "logging_service", "logging.googleapis.com"),
253+
),
254+
},
255+
{
256+
Config: testAccContainerCluster_updateLogging(clusterName),
257+
Check: resource.ComposeTestCheckFunc(
258+
testAccCheckContainerCluster(
259+
"google_container_cluster.with_logging"),
260+
resource.TestCheckResourceAttr("google_container_cluster.with_logging", "logging_service", "none"),
261+
),
262+
},
263+
},
264+
})
265+
}
266+
239267
func TestAccContainerCluster_withNodePoolBasic(t *testing.T) {
240268
resource.Test(t, resource.TestCase{
241269
PreCheck: func() { testAccPreCheck(t) },
@@ -838,6 +866,28 @@ resource "google_container_cluster" "primary" {
838866
}
839867
`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10))
840868

869+
func testAccContainerCluster_withLogging(clusterName string) string {
870+
return fmt.Sprintf(`
871+
resource "google_container_cluster" "with_logging" {
872+
name = "cluster-test-%s"
873+
zone = "us-central1-a"
874+
initial_node_count = 1
875+
876+
logging_service = "logging.googleapis.com"
877+
}`, clusterName)
878+
}
879+
880+
func testAccContainerCluster_updateLogging(clusterName string) string {
881+
return fmt.Sprintf(`
882+
resource "google_container_cluster" "with_logging" {
883+
name = "cluster-test-%s"
884+
zone = "us-central1-a"
885+
initial_node_count = 1
886+
887+
logging_service = "none"
888+
}`, clusterName)
889+
}
890+
841891
var testAccContainerCluster_withNodePoolBasic = fmt.Sprintf(`
842892
resource "google_container_cluster" "with_node_pool" {
843893
name = "tf-cluster-nodepool-test-%s"

0 commit comments

Comments
 (0)