diff --git a/.changelog/6468.txt b/.changelog/6468.txt new file mode 100644 index 00000000000..ee31d350a21 --- /dev/null +++ b/.changelog/6468.txt @@ -0,0 +1,3 @@ +```release-note:bug +container: fixed allow passing empty list to monitoring_config and logging_config in `google_container_cluster` +``` diff --git a/google/resource_container_cluster.go b/google/resource_container_cluster.go index a2fbe708c30..db3d1279724 100755 --- a/google/resource_container_cluster.go +++ b/google/resource_container_cluster.go @@ -3415,14 +3415,19 @@ func expandDnsConfig(configured interface{}) *container.DNSConfig { func expandContainerClusterLoggingConfig(configured interface{}) *container.LoggingConfig { l := configured.([]interface{}) - if len(l) == 0 || l[0] == nil { + if len(l) == 0 { return nil } - config := l[0].(map[string]interface{}) + var components []string + if l[0] != nil { + config := l[0].(map[string]interface{}) + components = convertStringArr(config["enable_components"].([]interface{})) + } + return &container.LoggingConfig{ ComponentConfig: &container.LoggingComponentConfig{ - EnableComponents: convertStringArr(config["enable_components"].([]interface{})), + EnableComponents: components, }, } } @@ -3435,7 +3440,7 @@ func expandMonitoringConfig(configured interface{}) *container.MonitoringConfig mc := &container.MonitoringConfig{} config := l[0].(map[string]interface{}) - if v, ok := config["enable_components"]; ok && len(v.([]interface{})) > 0 { + if v, ok := config["enable_components"]; ok { enable_components := v.([]interface{}) mc.ComponentConfig = &container.MonitoringComponentConfig{ EnableComponents: convertStringArr(enable_components), diff --git a/google/resource_container_cluster_test.go b/google/resource_container_cluster_test.go index 796216c4739..3cb8b6f4144 100755 --- a/google/resource_container_cluster_test.go +++ b/google/resource_container_cluster_test.go @@ -1923,6 +1923,14 @@ func TestAccContainerCluster_withLoggingConfig(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + Config: testAccContainerCluster_withLoggingConfigDisabled(clusterName), + }, + { + ResourceName: "google_container_cluster.primary", + ImportState: true, + ImportStateVerify: true, + }, { Config: testAccContainerCluster_withLoggingConfigUpdated(clusterName), }, @@ -1964,6 +1972,21 @@ func TestAccContainerCluster_withMonitoringConfig(t *testing.T) { { Config: testAccContainerCluster_withMonitoringConfigEnabled(clusterName), }, + { + ResourceName: "google_container_cluster.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"min_master_version"}, + }, + { + Config: testAccContainerCluster_withMonitoringConfigDisabled(clusterName), + }, + { + ResourceName: "google_container_cluster.primary", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"min_master_version"}, + }, { Config: testAccContainerCluster_basic_1_23_8(clusterName), }, @@ -4807,6 +4830,19 @@ resource "google_container_cluster" "primary" { `, name) } +func testAccContainerCluster_withLoggingConfigDisabled(name string) string { + return fmt.Sprintf(` +resource "google_container_cluster" "primary" { + name = "%s" + location = "us-central1-a" + initial_node_count = 1 + logging_config { + enable_components = [] + } +} +`, name) +} + func testAccContainerCluster_withLoggingConfigUpdated(name string) string { return fmt.Sprintf(` resource "google_container_cluster" "primary" { @@ -4848,6 +4884,19 @@ resource "google_container_cluster" "primary" { `, name) } +func testAccContainerCluster_withMonitoringConfigDisabled(name string) string { + return fmt.Sprintf(` +resource "google_container_cluster" "primary" { + name = "%s" + location = "us-central1-a" + initial_node_count = 1 + monitoring_config { + enable_components = [] + } +} +`, name) +} + func testAccContainerCluster_withSoleTenantGroup(name string) string { return fmt.Sprintf(` resource "google_compute_node_template" "soletenant-tmpl" {