diff --git a/kind/resource_cluster_test.go b/kind/resource_cluster_test.go index b18fdb1..1084461 100644 --- a/kind/resource_cluster_test.go +++ b/kind/resource_cluster_test.go @@ -142,6 +142,19 @@ func TestAccClusterConfigBase(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "kind_config.0.api_version", "kind.x-k8s.io/v1alpha4"), ), }, + { + Config: testAccClusterConfigAndExtraWithEmptyNetwork(clusterName), + Check: resource.ComposeTestCheckFunc( + testAccCheckClusterCreate(resourceName), + resource.TestCheckResourceAttr(resourceName, "name", clusterName), + resource.TestCheckNoResourceAttr(resourceName, "node_image"), + resource.TestCheckResourceAttr(resourceName, "wait_for_ready", "false"), + resource.TestCheckResourceAttr(resourceName, "kind_config.#", "1"), + resource.TestCheckResourceAttr(resourceName, "kind_config.0.kind", "Cluster"), + resource.TestCheckResourceAttr(resourceName, "kind_config.0.api_version", "kind.x-k8s.io/v1alpha4"), + resource.TestCheckResourceAttr(resourceName, "kind_config.0.networking.#", "1"), + ), + }, }, }) } @@ -639,3 +652,18 @@ resource "kind_cluster" "test" { } `, name) } + +func testAccClusterConfigAndExtraWithEmptyNetwork(name string) string { + return fmt.Sprintf(` +resource "kind_cluster" "test" { + name = "%s" + wait_for_ready = false + kind_config { + kind = "Cluster" + api_version = "kind.x-k8s.io/v1alpha4" + + networking {} + } +} +`, name) +} diff --git a/kind/schema_kind_config.go b/kind/schema_kind_config.go index 2dc7eb3..5fcb44a 100644 --- a/kind/schema_kind_config.go +++ b/kind/schema_kind_config.go @@ -132,7 +132,6 @@ func kindConfigNetworkingFields() map[string]*schema.Schema { }, "disable_default_cni": { Type: schema.TypeBool, - Default: false, Optional: true, }, "kube_proxy_mode": { diff --git a/kind/structure_kind_config.go b/kind/structure_kind_config.go index 366fbd5..07dd10d 100644 --- a/kind/structure_kind_config.go +++ b/kind/structure_kind_config.go @@ -23,8 +23,10 @@ func flattenKindConfig(d map[string]interface{}) *v1alpha4.Cluster { networking := mapKeyIfExists(d, "networking") if networking != nil { if n := networking.([]interface{}); len(n) == 1 { // MaxItems: 1, no more than one allowed so we don't have to loop here - data := n[0].(map[string]interface{}) - obj.Networking = flattenKindConfigNetworking(data) + if n[0] != nil { + data := n[0].(map[string]interface{}) + obj.Networking = flattenKindConfigNetworking(data) + } } } @@ -93,7 +95,7 @@ func flattenKindConfigNetworking(d map[string]interface{}) v1alpha4.Networking { apiServerPort := mapKeyIfExists(d, "api_server_port") if apiServerPort != nil { - obj.APIServerPort = apiServerPort.(int32) + obj.APIServerPort = int32(apiServerPort.(int)) } disableDefaultCNI := mapKeyIfExists(d, "disable_default_cni") @@ -174,11 +176,11 @@ func flattenKindConfigExtraPortMappings(d map[string]interface{}) v1alpha4.PortM containerPort := mapKeyIfExists(d, "container_port") if containerPort != nil { - obj.ContainerPort = containerPort.(int32) + obj.ContainerPort = int32(containerPort.(int)) } hostPort := mapKeyIfExists(d, "host_port") if hostPort != nil { - obj.HostPort = hostPort.(int32) + obj.HostPort = int32(hostPort.(int)) } listenAddress := mapKeyIfExists(d, "listen_address") if listenAddress != nil && listenAddress.(string) != "" {