Skip to content

Commit 0ee10f3

Browse files
authored
Merge pull request #223 from SumoLogic/avijit-monitors-schema-validations
Added validation for threshold_type
2 parents a5509a4 + b965583 commit 0ee10f3

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

sumologic/resource_sumologic_monitors_library_monitor.go

Lines changed: 12 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 {
@@ -90,30 +91,36 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource {
9091
"trigger_type": {
9192
Type: schema.TypeString,
9293
Optional: true,
94+
ValidateFunc: validation.StringInSlice([]string{"Critical","Warning","MissingData","ResolvedCritical","ResolvedWarning","ResolvedMissingData"}, false),
9395
},
9496
"threshold": {
9597
Type: schema.TypeFloat,
9698
Optional: true,
9799
},
98100
"threshold_type": {
99-
Type: schema.TypeString,
100-
Optional: true,
101+
Type: schema.TypeString,
102+
Optional: true,
103+
ValidateFunc: validation.StringInSlice([]string{"LessThan", "LessThanOrEqual", "GreaterThan", "GreaterThanOrEqual"}, false),
101104
},
102105
"time_range": {
103106
Type: schema.TypeString,
104107
Optional: true,
108+
ValidateFunc: validation.StringInSlice([]string{"5m","10m","15m","30m","60m","1h","3h","6h","12h","24h","1d"}, false),
105109
},
106110
"trigger_source": {
107111
Type: schema.TypeString,
108112
Optional: true,
113+
ValidateFunc: validation.StringInSlice([]string{"AllTimeSeries","AnyTimeSeries","AllResults"}, false),
109114
},
110115
"occurrence_type": {
111116
Type: schema.TypeString,
112117
Optional: true,
118+
ValidateFunc: validation.StringInSlice([]string{"AtLeastOnce","Always","ResultCount","MissingData"}, false),
113119
},
114120
"detection_method": {
115121
Type: schema.TypeString,
116122
Optional: true,
123+
ValidateFunc: validation.StringInSlice([]string{"StaticCondition","LogsStaticCondition","MetricsStaticCondition","LogsOutlierCondition","MetricsOutlierCondition","LogsMissingDataCondition","MetricsMissingDataCondition"}, false),
117124
},
118125
},
119126
},
@@ -142,6 +149,7 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource {
142149
Type: schema.TypeString,
143150
Optional: true,
144151
Computed: true,
152+
ValidateFunc: validation.StringInSlice([]string{"Email","AWSLambda","AzureFunctions","Datadog","HipChat","Jira","NewRelic","Opsgenie","PagerDuty","Slack","MicrosoftTeams","Webhook"}, false),
145153
},
146154
"subject": {
147155
Type: schema.TypeString,
@@ -198,6 +206,7 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource {
198206
"monitor_type": {
199207
Type: schema.TypeString,
200208
Required: true,
209+
ValidateFunc: validation.StringInSlice([]string{"Logs", "Metrics"}, false),
201210
},
202211

203212
"is_locked": {
@@ -223,6 +232,7 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource {
223232
Type: schema.TypeString,
224233
Optional: true,
225234
Default: "MonitorsLibraryMonitor",
235+
ValidateFunc: validation.StringInSlice([]string{"MonitorsLibraryMonitor", "MonitorsLibraryFolder"}, false),
226236
},
227237

228238
"modified_by": {

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)