From 22b2cc4629d3ff29083992df5e7488514a2873b7 Mon Sep 17 00:00:00 2001 From: Nico Kratky Date: Thu, 18 May 2023 17:22:48 +0200 Subject: [PATCH] Fix feature_gates (#39) * fix: type of feature_gates * fix: initialize maps before use * fix: RuntimeConfig and FeatureGates tests runtime_config and feature_gates were changed to maps, therefore the test cases also have to be changed to use the right syntax --- kind/resource_cluster_test.go | 10 ++++------ kind/structure_kind_config.go | 8 +++++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/kind/resource_cluster_test.go b/kind/resource_cluster_test.go index e0ff471..0b1fdd8 100644 --- a/kind/resource_cluster_test.go +++ b/kind/resource_cluster_test.go @@ -191,9 +191,8 @@ func TestAccClusterConfigBase(t *testing.T) { 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.runtime_config.#", "1"), - resource.TestCheckResourceAttr(resourceName, "kind_config.0.runtime_config.0", "api_alpha"), - resource.TestCheckResourceAttr(resourceName, "kind_config.0.runtime_config.0.api_alpha", "false"), + resource.TestCheckResourceAttr(resourceName, "kind_config.0.runtime_config.%", "1"), + resource.TestCheckResourceAttr(resourceName, "kind_config.0.runtime_config.api_alpha", "false"), ), }, { @@ -206,9 +205,8 @@ func TestAccClusterConfigBase(t *testing.T) { 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.feature_gates.#", "1"), - resource.TestCheckResourceAttr(resourceName, "kind_config.0.feature_gates.0", "CSINodeExpandSecret"), - resource.TestCheckResourceAttr(resourceName, "kind_config.0.feature_gates.0.CSINodeExpandSecret", "false"), + resource.TestCheckResourceAttr(resourceName, "kind_config.0.feature_gates.%", "1"), + resource.TestCheckResourceAttr(resourceName, "kind_config.0.feature_gates.CSINodeExpandSecret", "false"), ), }, }, diff --git a/kind/structure_kind_config.go b/kind/structure_kind_config.go index 4fe7128..b00fe70 100644 --- a/kind/structure_kind_config.go +++ b/kind/structure_kind_config.go @@ -43,17 +43,19 @@ func flattenKindConfig(d map[string]interface{}) *v1alpha4.Cluster { runtimeConfig := mapKeyIfExists(d, "runtime_config") if runtimeConfig != nil { data := runtimeConfig.(map[string]interface{}) + obj.RuntimeConfig = make(map[string]string) for k, v := range data { k = strings.ReplaceAll(k, "_", "/") // slash is not allowed in hcl, if there's an underscore replace with slash, e.g. `api_alpha` to `api/alpha` obj.RuntimeConfig[k] = v.(string) } } - featureGates := mapKeyIfExists(d, "features_gates") + featureGates := mapKeyIfExists(d, "feature_gates") if featureGates != nil { - data := featureGates.(map[string]string) + data := featureGates.(map[string]interface{}) + obj.FeatureGates = make(map[string]bool) for k, v := range data { - if strings.ToLower(v) == "true" { + if strings.ToLower(v.(string)) == "true" { obj.FeatureGates[k] = true } else { obj.FeatureGates[k] = false