Skip to content

Commit 2e7c427

Browse files
committed
Added validation for threshold_type
1 parent 17bf18d commit 2e7c427

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

sumologic/resource_sumologic_monitors_library_monitor.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66

77
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
8+
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
89
)
910

1011
func resourceSumologicMonitorsLibraryMonitor() *schema.Resource {
@@ -96,8 +97,9 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource {
9697
Optional: true,
9798
},
9899
"threshold_type": {
99-
Type: schema.TypeString,
100-
Optional: true,
100+
Type: schema.TypeString,
101+
Optional: true,
102+
ValidateFunc: validation.StringInSlice([]string{"LessThan", "LessThanOrEqual", "GreaterThan", "GreaterThanOrEqual"}, false),
101103
},
102104
"time_range": {
103105
Type: schema.TypeString,

sumologic/resource_sumologic_monitors_library_monitor_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package sumologic
22

33
import (
44
"fmt"
5+
"regexp"
56
"strconv"
67
"strings"
78
"testing"
@@ -11,6 +12,31 @@ import (
1112
"github.com/hashicorp/terraform-plugin-sdk/terraform"
1213
)
1314

15+
func TestAccSumologicMonitorsLibraryMonitor_schemaValidations(t *testing.T) {
16+
var monitorsLibraryMonitor MonitorsLibraryMonitor
17+
config := `
18+
resource "sumologic_monitor" "test" {
19+
name = "test"
20+
type = "MonitorsLibraryMonitor"
21+
monitor_type = "Logs"
22+
triggers {
23+
threshold_type = "foo"
24+
}
25+
}`
26+
expectedError := regexp.MustCompile(".*expected triggers.0.threshold_type to be one of \\[LessThan LessThanOrEqual GreaterThan GreaterThanOrEqual\\], got foo.*")
27+
resource.Test(t, resource.TestCase{
28+
Providers: testAccProviders,
29+
CheckDestroy: testAccCheckMonitorsLibraryMonitorDestroy(monitorsLibraryMonitor),
30+
Steps: []resource.TestStep{
31+
{
32+
Config: config,
33+
PlanOnly: true,
34+
ExpectError: expectedError,
35+
},
36+
},
37+
})
38+
}
39+
1440
func TestAccSumologicMonitorsLibraryMonitor_basic(t *testing.T) {
1541
var monitorsLibraryMonitor MonitorsLibraryMonitor
1642
testNameSuffix := acctest.RandString(16)

0 commit comments

Comments
 (0)