Skip to content

Commit 753b6f4

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

File tree

3 files changed

+61
-4
lines changed

3 files changed

+61
-4
lines changed

.changelog/6468.txt

+3
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/resource_container_cluster.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -3415,14 +3415,19 @@ func expandDnsConfig(configured interface{}) *container.DNSConfig {
34153415

34163416
func expandContainerClusterLoggingConfig(configured interface{}) *container.LoggingConfig {
34173417
l := configured.([]interface{})
3418-
if len(l) == 0 || l[0] == nil {
3418+
if len(l) == 0 {
34193419
return nil
34203420
}
34213421

3422-
config := l[0].(map[string]interface{})
3422+
var components []string
3423+
if l[0] != nil {
3424+
config := l[0].(map[string]interface{})
3425+
components = convertStringArr(config["enable_components"].([]interface{}))
3426+
}
3427+
34233428
return &container.LoggingConfig{
34243429
ComponentConfig: &container.LoggingComponentConfig{
3425-
EnableComponents: convertStringArr(config["enable_components"].([]interface{})),
3430+
EnableComponents: components,
34263431
},
34273432
}
34283433
}
@@ -3435,7 +3440,7 @@ func expandMonitoringConfig(configured interface{}) *container.MonitoringConfig
34353440
mc := &container.MonitoringConfig{}
34363441
config := l[0].(map[string]interface{})
34373442

3438-
if v, ok := config["enable_components"]; ok && len(v.([]interface{})) > 0 {
3443+
if v, ok := config["enable_components"]; ok {
34393444
enable_components := v.([]interface{})
34403445
mc.ComponentConfig = &container.MonitoringComponentConfig{
34413446
EnableComponents: convertStringArr(enable_components),

google/resource_container_cluster_test.go

+49
Original file line numberDiff line numberDiff line change
@@ -1923,6 +1923,14 @@ func TestAccContainerCluster_withLoggingConfig(t *testing.T) {
19231923
ImportState: true,
19241924
ImportStateVerify: true,
19251925
},
1926+
{
1927+
Config: testAccContainerCluster_withLoggingConfigDisabled(clusterName),
1928+
},
1929+
{
1930+
ResourceName: "google_container_cluster.primary",
1931+
ImportState: true,
1932+
ImportStateVerify: true,
1933+
},
19261934
{
19271935
Config: testAccContainerCluster_withLoggingConfigUpdated(clusterName),
19281936
},
@@ -1964,6 +1972,21 @@ func TestAccContainerCluster_withMonitoringConfig(t *testing.T) {
19641972
{
19651973
Config: testAccContainerCluster_withMonitoringConfigEnabled(clusterName),
19661974
},
1975+
{
1976+
ResourceName: "google_container_cluster.primary",
1977+
ImportState: true,
1978+
ImportStateVerify: true,
1979+
ImportStateVerifyIgnore: []string{"min_master_version"},
1980+
},
1981+
{
1982+
Config: testAccContainerCluster_withMonitoringConfigDisabled(clusterName),
1983+
},
1984+
{
1985+
ResourceName: "google_container_cluster.primary",
1986+
ImportState: true,
1987+
ImportStateVerify: true,
1988+
ImportStateVerifyIgnore: []string{"min_master_version"},
1989+
},
19671990
{
19681991
Config: testAccContainerCluster_basic_1_23_8(clusterName),
19691992
},
@@ -4807,6 +4830,19 @@ resource "google_container_cluster" "primary" {
48074830
`, name)
48084831
}
48094832

4833+
func testAccContainerCluster_withLoggingConfigDisabled(name string) string {
4834+
return fmt.Sprintf(`
4835+
resource "google_container_cluster" "primary" {
4836+
name = "%s"
4837+
location = "us-central1-a"
4838+
initial_node_count = 1
4839+
logging_config {
4840+
enable_components = []
4841+
}
4842+
}
4843+
`, name)
4844+
}
4845+
48104846
func testAccContainerCluster_withLoggingConfigUpdated(name string) string {
48114847
return fmt.Sprintf(`
48124848
resource "google_container_cluster" "primary" {
@@ -4848,6 +4884,19 @@ resource "google_container_cluster" "primary" {
48484884
`, name)
48494885
}
48504886

4887+
func testAccContainerCluster_withMonitoringConfigDisabled(name string) string {
4888+
return fmt.Sprintf(`
4889+
resource "google_container_cluster" "primary" {
4890+
name = "%s"
4891+
location = "us-central1-a"
4892+
initial_node_count = 1
4893+
monitoring_config {
4894+
enable_components = []
4895+
}
4896+
}
4897+
`, name)
4898+
}
4899+
48514900
func testAccContainerCluster_withSoleTenantGroup(name string) string {
48524901
return fmt.Sprintf(`
48534902
resource "google_compute_node_template" "soletenant-tmpl" {

0 commit comments

Comments
 (0)