From aca55a2f0ff49f8f46741e5bb039159cd8e8da52 Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Thu, 5 May 2022 08:21:41 -0500 Subject: [PATCH] Fix: error creating env0 resources --- env0/resource_configuration_variable.go | 5 ++++- env0/resource_configuration_variable_test.go | 21 ++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/env0/resource_configuration_variable.go b/env0/resource_configuration_variable.go index ccb47364..8b6d0cae 100644 --- a/env0/resource_configuration_variable.go +++ b/env0/resource_configuration_variable.go @@ -194,7 +194,10 @@ func getEnum(d *schema.ResourceData, selectedValue string) ([]string, diag.Diagn if specified, ok := d.GetOk("enum"); ok { enumValues = specified.([]interface{}) valueExists := false - for _, enumValue := range enumValues { + for i, enumValue := range enumValues { + if enumValue == nil { + return nil, diag.Errorf("an empty enum value is not allowed (at index %d)", i) + } actualEnumValues = append(actualEnumValues, enumValue.(string)) if enumValue == selectedValue { valueExists = true diff --git a/env0/resource_configuration_variable_test.go b/env0/resource_configuration_variable_test.go index 27b66ac6..ea049de7 100644 --- a/env0/resource_configuration_variable_test.go +++ b/env0/resource_configuration_variable_test.go @@ -323,6 +323,27 @@ resource "%s" "test" { runUnitTest(t, createTestCase, func(mock *client.MockApiClientInterface) {}) }) + t.Run("Create Enum with empty value", func(t *testing.T) { + stepConfig := fmt.Sprintf(` + resource "%s" "test" { + name = "%s" + description = "%s" + value= "%s" + enum = ["a",""] + }`, resourceType, configVar.Name, configVar.Description, configVar.Value) + + createTestCase := resource.TestCase{ + Steps: []resource.TestStep{ + { + Config: stepConfig, + ExpectError: regexp.MustCompile(`an empty enum value is not allowed \(at index 1\)`), + }, + }, + } + + runUnitTest(t, createTestCase, func(mock *client.MockApiClientInterface) {}) + }) + t.Run("Create with wrong type", func(t *testing.T) { createTestCase := resource.TestCase{ Steps: []resource.TestStep{