Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: error creating env0 resources #365

Merged
merged 2 commits into from
May 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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