Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(resource_container_cluster): allow passing empty list to monitoring_config and logging_config #12605

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/6468.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
container: fixed allow passing empty list to monitoring_config and logging_config in `google_container_cluster`
```
13 changes: 9 additions & 4 deletions google/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}
Expand All @@ -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),
Expand Down
49 changes: 49 additions & 0 deletions google/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand Down Expand Up @@ -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),
},
Expand Down Expand Up @@ -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" {
Expand Down Expand Up @@ -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"
<