Skip to content

Commit

Permalink
Fix: error creating env0 resources (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerHeber committed May 8, 2022
1 parent d9c29ac commit b4cca28
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion env0/resource_configuration_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions env0/resource_configuration_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit b4cca28

Please sign in to comment.