diff --git a/.secrets.baseline b/.secrets.baseline index 95cca36c56..6cab668923 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -3,7 +3,7 @@ "files": "go.mod|go.sum|.*.map|^.secrets.baseline$", "lines": null }, - "generated_at": "2024-03-05T13:58:58Z", + "generated_at": "2024-03-05T17:14:40Z", "plugins_used": [ { "name": "ArtifactoryDetector" diff --git a/ibm/service/catalogmanagement/resource_ibm_cm_validation.go b/ibm/service/catalogmanagement/resource_ibm_cm_validation.go index def2a8b3f8..3b1f2b5aac 100644 --- a/ibm/service/catalogmanagement/resource_ibm_cm_validation.go +++ b/ibm/service/catalogmanagement/resource_ibm_cm_validation.go @@ -225,7 +225,7 @@ func resourceIBMCmValidationCreate(context context.Context, d *schema.ResourceDa validateInstallOptions.SetOverrideValues(&overridesModel) } if _, ok := d.GetOk("environment_variables"); ok { - envsModel, err := envVariablesToDeployRequestBodyEnvVariables(d.Get("environment_variables").([]map[string]interface{})) + envsModel, err := envVariablesToDeployRequestBodyEnvVariables(d.Get("environment_variables").([]interface{})) if err != nil { return diag.FromErr(err) } @@ -409,20 +409,22 @@ func markVersionAsConsumable(version catalogmanagementv1.Version, context contex return nil } -func envVariablesToDeployRequestBodyEnvVariables(envVariables []map[string]interface{}) ([]catalogmanagementv1.DeployRequestBodyEnvironmentVariablesItem, error) { +func envVariablesToDeployRequestBodyEnvVariables(envVariables []interface{}) ([]catalogmanagementv1.DeployRequestBodyEnvironmentVariablesItem, error) { var modelArr []catalogmanagementv1.DeployRequestBodyEnvironmentVariablesItem for _, envVar := range envVariables { - model := catalogmanagementv1.DeployRequestBodyEnvironmentVariablesItem{} - if envVar["name"] != nil && envVar["name"].(string) != "" { - model.Name = core.StringPtr(envVar["name"].(string)) - } - if envVar["value"] != nil { - model.Value = envVar["value"] - } - if envVar["secure"] != nil { - model.Secure = core.BoolPtr(envVar["secure"].(bool)) + if envVar != nil { + model := catalogmanagementv1.DeployRequestBodyEnvironmentVariablesItem{} + if envVar.(map[string]interface{})["name"] != nil && envVar.(map[string]interface{})["name"].(string) != "" { + model.Name = core.StringPtr(envVar.(map[string]interface{})["name"].(string)) + } + if envVar.(map[string]interface{})["value"] != nil { + model.Value = envVar.(map[string]interface{})["value"] + } + if envVar.(map[string]interface{})["secure"] != nil { + model.Secure = core.BoolPtr(envVar.(map[string]interface{})["secure"].(bool)) + } + modelArr = append(modelArr, model) } - modelArr = append(modelArr, model) } return modelArr, nil } diff --git a/ibm/service/catalogmanagement/resource_ibm_cm_validation_test.go b/ibm/service/catalogmanagement/resource_ibm_cm_validation_test.go new file mode 100644 index 0000000000..9baf4112c7 --- /dev/null +++ b/ibm/service/catalogmanagement/resource_ibm_cm_validation_test.go @@ -0,0 +1,70 @@ +// Copyright IBM Corp. 2022 All Rights Reserved. +// Licensed under the Mozilla Public License v2.0 + +package catalogmanagement_test + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + + acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest" + "github.com/IBM/platform-services-go-sdk/catalogmanagementv1" +) + +func TestAccIBMCmValidationSimpleArgs(t *testing.T) { + var conf catalogmanagementv1.Version + versionLocator := "dba7e7dd-2bd7-4fcd-a846-4c370eab2672.98ba725b-86fa-4c6a-8430-70f38ec988da" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acc.TestAccPreCheck(t) }, + Providers: acc.TestAccProviders, + CheckDestroy: testAccCheckIBMCmValidationDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccCheckIBMCmValidationSimpleConfig(versionLocator), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckIBMCmValidationExists("ibm_cm_validation.cm_validation", conf), + resource.TestCheckResourceAttr("ibm_cm_validation.cm_validation", "version_locator", versionLocator), + ), + }, + }, + }) +} + +func testAccCheckIBMCmValidationSimpleConfig(versionLocator string) string { + return fmt.Sprintf(` + resource "ibm_cm_validation" "cm_validation" { + version_locator = "%s" + revalidate_if_validated = true + mark_version_consumable = false + + override_values = { + name = "My TF" + } + + environment_variables { + name = "test" + value = "test" + secure = true + } + + environment_variables { + + } + } + `, versionLocator) +} + +func testAccCheckIBMCmValidationExists(n string, obj catalogmanagementv1.Version) resource.TestCheckFunc { + + return func(s *terraform.State) error { + return nil + } +} + +func testAccCheckIBMCmValidationDestroy(s *terraform.State) error { + return nil +}