diff --git a/env0/resource_configuration_variable.go b/env0/resource_configuration_variable.go index d6849e85..e90f9dca 100644 --- a/env0/resource_configuration_variable.go +++ b/env0/resource_configuration_variable.go @@ -195,7 +195,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{