Skip to content

Commit f40558d

Browse files
fix(resource_container_cluster): allow passing empty list to monitoring_config and logging_config (#6468) (#4700)
Signed-off-by: Modular Magician <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent ca43279 commit f40558d

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

.changelog/6468.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
container: fixed allow passing empty list to monitoring_config and logging_config in `google_container_cluster`
3+
```

google-beta/resource_container_cluster.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4015,14 +4015,19 @@ func expandDnsConfig(configured interface{}) *container.DNSConfig {
40154015

40164016
func expandContainerClusterLoggingConfig(configured interface{}) *container.LoggingConfig {
40174017
l := configured.([]interface{})
4018-
if len(l) == 0 || l[0] == nil {
4018+
if len(l) == 0 {
40194019
return nil
40204020
}
40214021

4022-
config := l[0].(map[string]interface{})
4022+
var components []string
4023+
if l[0] != nil {
4024+
config := l[0].(map[string]interface{})
4025+
components = convertStringArr(config["enable_components"].([]interface{}))
4026+
}
4027+
40234028
return &container.LoggingConfig{
40244029
ComponentConfig: &container.LoggingComponentConfig{
4025-
EnableComponents: convertStringArr(config["enable_components"].([]interface{})),
4030+
EnableComponents: components,
40264031
},
40274032
}
40284033
}
@@ -4035,7 +4040,7 @@ func expandMonitoringConfig(configured interface{}) *container.MonitoringConfig
40354040
mc := &container.MonitoringConfig{}
40364041
config := l[0].(map[string]interface{})
40374042

4038-
if v, ok := config["enable_components"]; ok && len(v.([]interface{})) > 0 {
4043+
if v, ok := config["enable_components"]; ok {
40394044
enable_components := v.([]interface{})
40404045
mc.ComponentConfig = &container.MonitoringComponentConfig{
40414046
EnableComponents: convertStringArr(enable_components),

google-beta/resource_container_cluster_test.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,6 +2236,14 @@ func TestAccContainerCluster_withLoggingConfig(t *testing.T) {
22362236
ImportState: true,
22372237
ImportStateVerify: true,
22382238
},
2239+
{
2240+
Config: testAccContainerCluster_withLoggingConfigDisabled(clusterName),
2241+
},
2242+
{
2243+
ResourceName: "google_container_cluster.primary",
2244+
ImportState: true,
2245+
ImportStateVerify: true,
2246+
},
22392247
{
22402248
Config: testAccContainerCluster_withLoggingConfigUpdated(clusterName),
22412249
},
@@ -2283,6 +2291,15 @@ func TestAccContainerCluster_withMonitoringConfig(t *testing.T) {
22832291
ImportStateVerify: true,
22842292
ImportStateVerifyIgnore: []string{"min_master_version"},
22852293
},
2294+
{
2295+
Config: testAccContainerCluster_withMonitoringConfigDisabled(clusterName),
2296+
},
2297+
{
2298+
ResourceName: "google_container_cluster.primary",
2299+
ImportState: true,
2300+
ImportStateVerify: true,
2301+
ImportStateVerifyIgnore: []string{"min_master_version"},
2302+
},
22862303
{
22872304
Config: testAccContainerCluster_withMonitoringConfigUpdated(clusterName),
22882305
},
@@ -6010,6 +6027,19 @@ resource "google_container_cluster" "primary" {
60106027
`, name)
60116028
}
60126029

6030+
func testAccContainerCluster_withLoggingConfigDisabled(name string) string {
6031+
return fmt.Sprintf(`
6032+
resource "google_container_cluster" "primary" {
6033+
name = "%s"
6034+
location = "us-central1-a"
6035+
initial_node_count = 1
6036+
logging_config {
6037+
enable_components = []
6038+
}
6039+
}
6040+
`, name)
6041+
}
6042+
60136043
func testAccContainerCluster_withLoggingConfigUpdated(name string) string {
60146044
return fmt.Sprintf(`
60156045
resource "google_container_cluster" "primary" {
@@ -6051,6 +6081,19 @@ resource "google_container_cluster" "primary" {
60516081
`, name)
60526082
}
60536083

6084+
func testAccContainerCluster_withMonitoringConfigDisabled(name string) string {
6085+
return fmt.Sprintf(`
6086+
resource "google_container_cluster" "primary" {
6087+
name = "%s"
6088+
location = "us-central1-a"
6089+
initial_node_count = 1
6090+
monitoring_config {
6091+
enable_components = []
6092+
}
6093+
}
6094+
`, name)
6095+
}
6096+
60546097
func testAccContainerCluster_withMonitoringConfigUpdated(name string) string {
60556098
return fmt.Sprintf(`
60566099
resource "google_container_cluster" "primary" {

0 commit comments

Comments
 (0)