diff --git a/selectel/data_source_selectel_mks_kube_options.go b/selectel/data_source_selectel_mks_kube_options.go index 88043821..78d59aa2 100644 --- a/selectel/data_source_selectel_mks_kube_options.go +++ b/selectel/data_source_selectel_mks_kube_options.go @@ -57,6 +57,7 @@ func dataSourceMKSFeatureGatesV1() *schema.Resource { Elem: &schema.Schema{ Type: schema.TypeString, }, + Set: schema.HashString, }, }, }, @@ -183,6 +184,7 @@ func dataSourceMKSAdmissionControllersV1() *schema.Resource { Elem: &schema.Schema{ Type: schema.TypeString, }, + Set: schema.HashString, }, }, }, @@ -214,6 +216,8 @@ func dataSourceMKSAdmissionControllersV1Read(ctx context.Context, d *schema.Reso return diag.FromErr(err) } d.SetId(checksum) + + return nil } filterMap := filterSet.List()[0].(map[string]interface{}) diff --git a/selectel/data_source_selectel_mks_kube_options_test.go b/selectel/data_source_selectel_mks_kube_options_test.go index 5114924e..06e9e21b 100644 --- a/selectel/data_source_selectel_mks_kube_options_test.go +++ b/selectel/data_source_selectel_mks_kube_options_test.go @@ -68,7 +68,11 @@ func TestAccMKSAvailableAdmissionControllersV1Basic(t *testing.T) { var project projects.Project projectName := acctest.RandomWithPrefix("tf-acc") - kubeVersion := "1.17.3" + kubeVersion := testAccMKSClusterV1GetDefaultKubeVersion(t) + kubeVersionMinor, err := kubeVersionTrimToMinor(kubeVersion) + if err != nil { + t.Fatal(err) + } resource.Test(t, resource.TestCase{ PreCheck: func() { testAccSelectelPreCheck(t) }, @@ -79,7 +83,7 @@ func TestAccMKSAvailableAdmissionControllersV1Basic(t *testing.T) { Config: testKubeOptionsV1BasicConfig(projectName, dataSourceAdmissionControllers, kubeVersion), Check: resource.ComposeTestCheckFunc( testAccCheckVPCV2ProjectExists("selectel_vpc_project_v2.project_tf_acc_test_1", &project), - resource.TestCheckResourceAttr("data."+dataSourceAdmissionControllers+".dt", "admission_controllers.0.kube_version_minor", kubeVersion), + resource.TestCheckResourceAttr("data."+dataSourceAdmissionControllers+".dt", "admission_controllers.0.kube_version_minor", kubeVersionMinor), testAdmissionControllersIsNotEmpty("data."+dataSourceAdmissionControllers+".dt"), ), }, @@ -115,7 +119,8 @@ func testFeatureGatesIsNotEmpty(n string) resource.TestCheckFunc { return fmt.Errorf("not found: %s", n) } - availableFeatureGates, ok := rs.Primary.Attributes["feature_gates.0.names"] + availableFeatureGates, ok := rs.Primary.Attributes["feature_gates.#"] + //availableFeatureGates, ok := rs.Primary.Attributes["feature_gates.0.names.0"] if !ok { return fmt.Errorf("attribute 'feature_gates' is not found") } @@ -134,7 +139,7 @@ func testFeatureGatesNoFilter(n string) resource.TestCheckFunc { return fmt.Errorf("not found: %s", n) } - availableFeatureGates, ok := rs.Primary.Attributes["feature_gates.0.names"] + availableFeatureGates, ok := rs.Primary.Attributes["feature_gates.0.names.#"] if !ok { return fmt.Errorf("attribute 'feature_gates' is not found") } @@ -142,11 +147,11 @@ func testFeatureGatesNoFilter(n string) resource.TestCheckFunc { return fmt.Errorf("names is not set at 'feature_gates'") } - fgLen, err := strconv.Atoi(rs.Primary.Attributes["feature_gates.#"]) + fgCount, err := strconv.Atoi(availableFeatureGates) if err != nil { return fmt.Errorf("failed to get len of 'feature_gates': %w", err) } - if fgLen <= 1 { + if fgCount <= 1 { return fmt.Errorf("received only one or less item in 'feature_gates'") } @@ -161,7 +166,7 @@ func testAdmissionControllersIsNotEmpty(n string) resource.TestCheckFunc { return fmt.Errorf("not found: %s", n) } - availableAdmissionControllers, ok := rs.Primary.Attributes["admission_controllers.0.names"] + availableAdmissionControllers, ok := rs.Primary.Attributes["admission_controllers.#"] if !ok { return fmt.Errorf("attribute 'admission_controllers' is not found") } @@ -180,7 +185,7 @@ func testAdmissionControllersNoFilter(n string) resource.TestCheckFunc { return fmt.Errorf("not found: %s", n) } - availableAdmissionControllers, ok := rs.Primary.Attributes["admission_controllers.0.names"] + availableAdmissionControllers, ok := rs.Primary.Attributes["admission_controllers.0.names.#"] if !ok { return fmt.Errorf("attribute 'admission_controllers' is not found") } @@ -188,11 +193,11 @@ func testAdmissionControllersNoFilter(n string) resource.TestCheckFunc { return fmt.Errorf("names is not set at 'admission_controllers'") } - fgLen, err := strconv.Atoi(rs.Primary.Attributes["admission_controllers.#"]) + acCount, err := strconv.Atoi(availableAdmissionControllers) if err != nil { return fmt.Errorf("failed to get len of 'admission_controllers': %w", err) } - if fgLen <= 1 { + if acCount <= 1 { return fmt.Errorf("received only one or less item in 'admission_controllers'") } diff --git a/selectel/mks.go b/selectel/mks.go index 7272c83d..7abd2eb4 100644 --- a/selectel/mks.go +++ b/selectel/mks.go @@ -479,10 +479,10 @@ func flattenFeatureGatesFromSlice(kubeVersion string, featureGates []string) []i func flattenAdmissionControllers(views []*kubeoptions.View) []interface{} { availableAdmissionControllers := make([]interface{}, len(views)) - for i, fg := range views { + for i, ac := range views { availableAdmissionControllers[i] = map[string]interface{}{ - "kube_version_minor": fg.KubeVersion, - "names": strings.Join(fg.Names, ","), + "kube_version_minor": ac.KubeVersion, + "names": ac.Names, } } @@ -493,7 +493,7 @@ func flattenAdmissionControllersFromSlice(kubeVersion string, admissionControlle availableAdmissionControllers := make([]interface{}, 1) availableAdmissionControllers[0] = map[string]interface{}{ "kube_version_minor": kubeVersion, - "names": strings.Join(admissionControllers, ","), + "names": admissionControllers, } return availableAdmissionControllers