Skip to content

Commit 5d0ebf9

Browse files
Merge pull request #442 from SumoLogic/mzochowski-201717-add-supression-diff-rule-for-time-formats
Add suppression diff rule for time formats
2 parents 7ff2096 + d01b2b8 commit 5d0ebf9

File tree

6 files changed

+406
-39
lines changed

6 files changed

+406
-39
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 2.19.2 (Unreleased)
22
ENHANCEMENTS:
3+
* Suppress diffs for equivalent values of some time attributes. This should reduce output of `terraform plan` that didn't disappear after running `terraform apply`. (GH-442)
34
* Add better validation and documentation for some time attributes (GH-443)
45

56
## 2.19.1 (October 6, 2022)

sumologic/resource_sumologic_dashboard_test.go

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ func TestAccSumologicDashboard_create(t *testing.T) {
5151
refreshInterval := 120
5252
domain := "aws"
5353
literalRangeName := "today"
54+
relativeTime := "-60m"
55+
canonicalRelativeTime := "-1h"
5456
textPanel := TextPanel{
5557
Key: "text-panel-001",
5658
Title: "Text Panel Title",
@@ -84,7 +86,7 @@ func TestAccSumologicDashboard_create(t *testing.T) {
8486
Steps: []resource.TestStep{
8587
{
8688
Config: dashboardCreateConfig(title, description, theme, refreshInterval,
87-
topologyLabel, domain, literalRangeName, textPanel, layout, variable),
89+
topologyLabel, domain, literalRangeName, relativeTime, textPanel, layout, variable),
8890
Check: resource.ComposeTestCheckFunc(
8991
testAccCheckDashboardExists("sumologic_dashboard.tf_crud_test", &dashboard, t),
9092
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
@@ -104,6 +106,9 @@ func TestAccSumologicDashboard_create(t *testing.T) {
104106
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
105107
"time_range.0.begin_bounded_time_range.0.from.0.literal_time_range.0.range_name",
106108
literalRangeName),
109+
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
110+
"time_range.0.begin_bounded_time_range.0.to.0.relative_time_range.0.relative_time",
111+
canonicalRelativeTime),
107112
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
108113
"panel.#", "1"),
109114
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
@@ -133,6 +138,8 @@ func TestAccSumologicDashboard_update(t *testing.T) {
133138
refreshInterval := 120
134139
domain := "aws"
135140
literalRangeName := "today"
141+
relativeTime := "-1h"
142+
canonicalRelativeTime := "-1h"
136143
textPanel := TextPanel{
137144
Key: "text-panel-001",
138145
Title: "Text Panel Title",
@@ -164,6 +171,8 @@ func TestAccSumologicDashboard_update(t *testing.T) {
164171
newFirstLabelValue := "collection-cluster"
165172
updatedDomain := "app"
166173
newLiteralRangeName := "week"
174+
newRelativeTime := "60s"
175+
canonicalNewRelativeTime := "1m"
167176
searchPanel := SumoSearchPanel{
168177
Key: "search-panel-001",
169178
Title: "API Errors",
@@ -214,7 +223,7 @@ func TestAccSumologicDashboard_update(t *testing.T) {
214223
Steps: []resource.TestStep{
215224
{
216225
Config: dashboardCreateConfig(title, description, theme, refreshInterval,
217-
topologyLabel, domain, literalRangeName, textPanel, layout, csvVariable),
226+
topologyLabel, domain, literalRangeName, relativeTime, textPanel, layout, csvVariable),
218227
Check: resource.ComposeTestCheckFunc(
219228
testAccCheckDashboardExists("sumologic_dashboard.tf_crud_test", &dashboard, t),
220229
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
@@ -230,6 +239,9 @@ func TestAccSumologicDashboard_update(t *testing.T) {
230239
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
231240
"time_range.0.begin_bounded_time_range.0.from.0.literal_time_range.0.range_name",
232241
literalRangeName),
242+
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
243+
"time_range.0.begin_bounded_time_range.0.to.0.relative_time_range.0.relative_time",
244+
canonicalRelativeTime),
233245
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
234246
"panel.#", "1"),
235247
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
@@ -246,7 +258,7 @@ func TestAccSumologicDashboard_update(t *testing.T) {
246258
},
247259
{
248260
Config: dashboardUpdateConfig(title, description, newTheme, newRefreshInterval,
249-
firstLabelKey, newFirstLabelValue, updatedDomain, newLiteralRangeName, textPanel,
261+
firstLabelKey, newFirstLabelValue, updatedDomain, newLiteralRangeName, newRelativeTime, textPanel,
250262
searchPanel, newLayout, newVariables),
251263
Check: resource.ComposeTestCheckFunc(
252264
testAccCheckDashboardExists("sumologic_dashboard.tf_crud_test", &dashboard, t),
@@ -263,6 +275,9 @@ func TestAccSumologicDashboard_update(t *testing.T) {
263275
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
264276
"time_range.0.begin_bounded_time_range.0.from.0.literal_time_range.0.range_name",
265277
newLiteralRangeName),
278+
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
279+
"time_range.0.begin_bounded_time_range.0.to.0.relative_time_range.0.relative_time",
280+
canonicalNewRelativeTime),
266281
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
267282
"panel.#", "2"),
268283
resource.TestCheckResourceAttr("sumologic_dashboard.tf_crud_test",
@@ -412,7 +427,7 @@ func dashboardImportConfig(title string) string {
412427
}
413428

414429
func dashboardCreateConfig(title string, description string, theme string, refreshInterval int,
415-
topologyLabel TopologyLabel, domain string, rangeName string, textPanel TextPanel,
430+
topologyLabel TopologyLabel, domain string, rangeName string, relativeTime string, textPanel TextPanel,
416431
layout GridLayout, variable Variable) string {
417432

418433
return fmt.Sprintf(`
@@ -441,6 +456,12 @@ func dashboardCreateConfig(title string, description string, theme string, refre
441456
range_name = "%s"
442457
}
443458
}
459+
460+
to {
461+
relative_time_range {
462+
relative_time = "%s"
463+
}
464+
}
444465
}
445466
}
446467
panel {
@@ -476,14 +497,14 @@ func dashboardCreateConfig(title string, description string, theme string, refre
476497
}`,
477498
title, description, refreshInterval, theme, firstLabelKey, topologyLabel.Data[firstLabelKey][0],
478499
secondLabelKey, topologyLabel.Data[secondLabelKey][0], topologyLabel.Data[secondLabelKey][1],
479-
domain, rangeName, textPanel.Key, textPanel.Title, textPanel.Text,
500+
domain, rangeName, relativeTime, textPanel.Key, textPanel.Title, textPanel.Text,
480501
layout.LayoutStructures[0].Key, variable.Name, variable.DisplayName, variable.DefaultValue,
481502
variable.SourceDefinition.(CsvVariableSourceDefinition).Values,
482503
)
483504
}
484505

485506
func dashboardUpdateConfig(title string, description string, theme string, refreshInterval int,
486-
topologyLabel string, topologyLabelValue string, domain string, rangeName string,
507+
topologyLabel string, topologyLabelValue string, domain string, rangeName string, relativeTime string,
487508
textPanel TextPanel, searchPanel SumoSearchPanel, layout GridLayout,
488509
variables []Variable) string {
489510

@@ -512,6 +533,12 @@ func dashboardUpdateConfig(title string, description string, theme string, refre
512533
range_name = "%s"
513534
}
514535
}
536+
537+
to {
538+
relative_time_range {
539+
relative_time = "%s"
540+
}
541+
}
515542
}
516543
}
517544
panel {
@@ -540,7 +567,7 @@ func dashboardUpdateConfig(title string, description string, theme string, refre
540567
begin_bounded_time_range {
541568
from {
542569
relative_time_range {
543-
relative_time = "-1d"
570+
relative_time = "-60m"
544571
}
545572
}
546573
}
@@ -588,7 +615,7 @@ func dashboardUpdateConfig(title string, description string, theme string, refre
588615
}
589616
}`,
590617
title, description, refreshInterval, theme, topologyLabel, topologyLabelValue, domain,
591-
rangeName, textPanel.Key, textPanel.Title, textPanel.Text,
618+
rangeName, relativeTime, textPanel.Key, textPanel.Title, textPanel.Text,
592619
searchPanel.Key, searchPanel.Title, searchPanel.Description, searchPanel.Queries[0].QueryString,
593620
searchPanel.Queries[0].QueryKey,
594621
layout.LayoutStructures[0].Key, layout.LayoutStructures[1].Key,

sumologic/resource_sumologic_monitors_library_monitor.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource {
105105
ValidateFunc: validation.StringInSlice([]string{"LessThan", "LessThanOrEqual", "GreaterThan", "GreaterThanOrEqual"}, false),
106106
},
107107
"time_range": {
108-
Type: schema.TypeString,
109-
Optional: true,
110-
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^-?(\d)+[smhd]$`), "Time range must be in the format '-?\\d+[smhd]'. Examples: -15m, 1d, etc."),
108+
Type: schema.TypeString,
109+
Optional: true,
110+
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^-?(\d)+[smhd]$`), "Time range must be in the format '-?\\d+[smhd]'. Examples: -15m, 1d, etc."),
111+
DiffSuppressFunc: SuppressEquivalentTimeDiff(false),
111112
},
112113
"trigger_source": {
113114
Type: schema.TypeString,
@@ -292,10 +293,11 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource {
292293
},
293294

294295
"evaluation_delay": {
295-
Type: schema.TypeString,
296-
Optional: true,
297-
Computed: true,
298-
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^((\d)+[smh])+$`), "This value is not in correct format. Example: 1m30s"),
296+
Type: schema.TypeString,
297+
Optional: true,
298+
Computed: true,
299+
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^((\d)+[smh])+$`), "This value is not in correct format. Example: 1m30s"),
300+
DiffSuppressFunc: SuppressEquivalentTimeDiff(false),
299301
},
300302

301303
"is_locked": {
@@ -547,15 +549,17 @@ var consecutiveSchema = schema.Schema{
547549
}
548550

549551
var timeRangeSchema = schema.Schema{
550-
Type: schema.TypeString,
551-
Required: true,
552-
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^-?(\d)+[smhd]$`), "Time range must be in the format '-?\\d+[smhd]'. Examples: -15m, 1d, etc."),
552+
Type: schema.TypeString,
553+
Required: true,
554+
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^-?(\d)+[smhd]$`), "Time range must be in the format '-?\\d+[smhd]'. Examples: -15m, 1d, etc."),
555+
DiffSuppressFunc: SuppressEquivalentTimeDiff(false),
553556
}
554557

555558
var resolutionWindowSchema = schema.Schema{
556-
Type: schema.TypeString,
557-
Optional: true,
558-
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^(\d)+[smhd]$`), "Resolution window must be in the format '\\d+[smhd]'. Examples: 0m, 15m, 1d, etc."),
559+
Type: schema.TypeString,
560+
Optional: true,
561+
ValidateFunc: validation.StringMatch(regexp.MustCompile(`^(\d)+[smhd]`), "Resolution window must be in the format '\\d+[smhd]'. Examples: 0m, 15m, 1d, etc."),
562+
DiffSuppressFunc: SuppressEquivalentTimeDiff(false),
559563
}
560564

561565
var thresholdSchema = schema.Schema{

sumologic/resource_sumologic_monitors_library_monitor_test.go

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,24 @@ func TestAccSumologicMonitorsLibraryMonitor_schemaValidations(t *testing.T) {
106106
})
107107
}
108108

109+
func TestAccSumologicMonitorsLibraryMonitor_triggersTimeRangeDiffSuppression(t *testing.T) {
110+
var monitorsLibraryMonitor MonitorsLibraryMonitor
111+
canonicalTimeRange := "1h"
112+
113+
resource.Test(t, resource.TestCase{
114+
Providers: testAccProviders,
115+
CheckDestroy: testAccCheckMonitorsLibraryMonitorDestroy(monitorsLibraryMonitor),
116+
Steps: []resource.TestStep{
117+
{
118+
Config: testAccSumologicMonitorsLibraryMonitor("triggers_negative_expanded_hour"),
119+
Check: resource.ComposeTestCheckFunc(
120+
resource.TestCheckResourceAttr("sumologic_monitor.test", "triggers.0.time_range", canonicalTimeRange),
121+
),
122+
},
123+
},
124+
})
125+
}
126+
109127
func TestAccSumologicMonitorsLibraryMonitor_basic(t *testing.T) {
110128
var monitorsLibraryMonitor MonitorsLibraryMonitor
111129
testNameSuffix := acctest.RandString(16)
@@ -138,7 +156,7 @@ func TestAccSumologicMonitorsLibraryMonitor_create(t *testing.T) {
138156
testContentType := "Monitor"
139157
testMonitorType := "Logs"
140158
testIsDisabled := false
141-
testEvaluationDelay := "5m"
159+
canonicalTestEvaluationDelay := "1h"
142160
testQueries := []MonitorQuery{
143161
{
144162
RowID: "A",
@@ -149,7 +167,7 @@ func TestAccSumologicMonitorsLibraryMonitor_create(t *testing.T) {
149167
{
150168
ThresholdType: "GreaterThan",
151169
Threshold: 40.0,
152-
TimeRange: "15m",
170+
TimeRange: "1h",
153171
OccurrenceType: "ResultCount",
154172
TriggerSource: "AllResults",
155173
TriggerType: "Critical",
@@ -158,7 +176,7 @@ func TestAccSumologicMonitorsLibraryMonitor_create(t *testing.T) {
158176
{
159177
ThresholdType: "LessThanOrEqual",
160178
Threshold: 40.0,
161-
TimeRange: "15m",
179+
TimeRange: "1h",
162180
OccurrenceType: "ResultCount",
163181
TriggerSource: "AllResults",
164182
TriggerType: "ResolvedCritical",
@@ -207,7 +225,7 @@ func TestAccSumologicMonitorsLibraryMonitor_create(t *testing.T) {
207225
resource.TestCheckResourceAttr("sumologic_monitor.test", "name", testName),
208226
resource.TestCheckResourceAttr("sumologic_monitor.test", "type", testType),
209227
resource.TestCheckResourceAttr("sumologic_monitor.test", "description", testDescription),
210-
resource.TestCheckResourceAttr("sumologic_monitor.test", "evaluation_delay", testEvaluationDelay),
228+
resource.TestCheckResourceAttr("sumologic_monitor.test", "evaluation_delay", canonicalTestEvaluationDelay),
211229
resource.TestCheckResourceAttr("sumologic_monitor.test", "content_type", testContentType),
212230
resource.TestCheckResourceAttr("sumologic_monitor.test", "queries.0.row_id", testQueries[0].RowID),
213231
resource.TestCheckResourceAttr("sumologic_monitor.test", "triggers.0.trigger_type", testTriggers[0].TriggerType),
@@ -305,7 +323,7 @@ func TestAccSumologicMonitorsLibraryMonitor_update(t *testing.T) {
305323
testMonitorType := "Logs"
306324
testPlaybook := "This is a test playbook"
307325
testIsDisabled := false
308-
testEvaluationDelay := "5m"
326+
canonicalTestEvaluationDelay := "1h"
309327
testQueries := []MonitorQuery{
310328
{
311329
RowID: "A",
@@ -316,7 +334,7 @@ func TestAccSumologicMonitorsLibraryMonitor_update(t *testing.T) {
316334
{
317335
ThresholdType: "GreaterThan",
318336
Threshold: 40.0,
319-
TimeRange: "15m",
337+
TimeRange: "1h",
320338
OccurrenceType: "ResultCount",
321339
TriggerSource: "AllResults",
322340
TriggerType: "Critical",
@@ -325,7 +343,7 @@ func TestAccSumologicMonitorsLibraryMonitor_update(t *testing.T) {
325343
{
326344
ThresholdType: "LessThanOrEqual",
327345
Threshold: 40.0,
328-
TimeRange: "15m",
346+
TimeRange: "1h",
329347
OccurrenceType: "ResultCount",
330348
TriggerSource: "AllResults",
331349
TriggerType: "ResolvedCritical",
@@ -436,7 +454,7 @@ func TestAccSumologicMonitorsLibraryMonitor_update(t *testing.T) {
436454
resource.TestCheckResourceAttr("sumologic_monitor.test", "name", testName),
437455
resource.TestCheckResourceAttr("sumologic_monitor.test", "type", testType),
438456
resource.TestCheckResourceAttr("sumologic_monitor.test", "description", testDescription),
439-
resource.TestCheckResourceAttr("sumologic_monitor.test", "evaluation_delay", testEvaluationDelay),
457+
resource.TestCheckResourceAttr("sumologic_monitor.test", "evaluation_delay", canonicalTestEvaluationDelay),
440458
resource.TestCheckResourceAttr("sumologic_monitor.test", "content_type", testContentType),
441459
resource.TestCheckResourceAttr("sumologic_monitor.test", "queries.0.row_id", testQueries[0].RowID),
442460
resource.TestCheckResourceAttr("sumologic_monitor.test", "triggers.0.trigger_type", testTriggers[0].TriggerType),
@@ -697,15 +715,15 @@ resource "sumologic_monitor" "test" {
697715
is_disabled = false
698716
content_type = "Monitor"
699717
monitor_type = "Logs"
700-
evaluation_delay = "5m"
718+
evaluation_delay = "60m"
701719
queries {
702720
row_id = "A"
703721
query = "_sourceCategory=monitor-manager error"
704722
}
705723
triggers {
706724
threshold_type = "GreaterThan"
707725
threshold = 40.0
708-
time_range = "15m"
726+
time_range = "-60m"
709727
occurrence_type = "ResultCount"
710728
trigger_source = "AllResults"
711729
trigger_type = "Critical"
@@ -714,7 +732,7 @@ resource "sumologic_monitor" "test" {
714732
triggers {
715733
threshold_type = "LessThanOrEqual"
716734
threshold = 40.0
717-
time_range = "15m"
735+
time_range = "-60m"
718736
occurrence_type = "ResultCount"
719737
trigger_source = "AllResults"
720738
trigger_type = "ResolvedCritical"
@@ -1040,7 +1058,7 @@ resource "sumologic_monitor" "test" {
10401058
var exampleLogsStaticTriggerConditionBlock = `
10411059
logs_static_condition {
10421060
critical {
1043-
time_range = "30m"
1061+
time_range = "60m"
10441062
alert {
10451063
threshold = 100.0
10461064
threshold_type = "GreaterThan"
@@ -1056,15 +1074,15 @@ var exampleLogsStaticTriggerConditionBlock = `
10561074
var exampleLogsStaticTriggerConditionBlockWithResolutionWindow = `
10571075
logs_static_condition {
10581076
critical {
1059-
time_range = "30m"
1077+
time_range = "1h"
10601078
alert {
10611079
threshold = 100.0
10621080
threshold_type = "GreaterThan"
10631081
}
10641082
resolution {
10651083
threshold = 90
10661084
threshold_type = "LessThanOrEqual"
1067-
resolution_window = "15m"
1085+
resolution_window = "60m"
10681086
}
10691087
}
10701088
field = "field"
@@ -1073,7 +1091,7 @@ var exampleLogsStaticTriggerConditionBlockWithResolutionWindow = `
10731091
var exampleMetricsStaticTriggerConditionBlock1 = `
10741092
metrics_static_condition {
10751093
critical {
1076-
time_range = "30m"
1094+
time_range = "-30m"
10771095
occurrence_type = "AtLeastOnce"
10781096
alert {
10791097
threshold = 100.0

0 commit comments

Comments
 (0)