Skip to content

Commit ca211f9

Browse files
committed
SUMO-207606, addressed test failures and linter issues
1 parent ec27266 commit ca211f9

File tree

2 files changed

+57
-33
lines changed

2 files changed

+57
-33
lines changed

sumologic/resource_sumologic_monitors_library_monitor.go

Lines changed: 49 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,6 @@ import (
99
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
1010
)
1111

12-
var (
13-
triggerConditionsAtleatOneKey = []string{
14-
"trigger_conditions.0.logs_static_condition",
15-
"trigger_conditions.0.metrics_static_condition",
16-
"trigger_conditions.0.logs_outlier_condition",
17-
"trigger_conditions.0.metrics_outlier_condition",
18-
"trigger_conditions.0.logs_missing_data_condition",
19-
"trigger_conditions.0.metrics_missing_data_condition",
20-
"trigger_conditions.0.slo_sli_condition",
21-
"trigger_conditions.0.slo_burn_rate_condition",
22-
}
23-
criticalOrWarningAtleastOneKeys = []string{
24-
"trigger_conditions.0.logs_static_condition.0.warning",
25-
"trigger_conditions.0.logs_static_condition.0.critical",
26-
}
27-
)
28-
2912
func resourceSumologicMonitorsLibraryMonitor() *schema.Resource {
3013
return &schema.Resource{
3114
Create: resourceSumologicMonitorsLibraryMonitorCreate,
@@ -389,6 +372,43 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource {
389372
}
390373
}
391374

375+
var (
376+
triggerConditionsAtleatOneKey = []string{
377+
"trigger_conditions.0.logs_static_condition",
378+
"trigger_conditions.0.metrics_static_condition",
379+
"trigger_conditions.0.logs_outlier_condition",
380+
"trigger_conditions.0.metrics_outlier_condition",
381+
"trigger_conditions.0.logs_missing_data_condition",
382+
"trigger_conditions.0.metrics_missing_data_condition",
383+
"trigger_conditions.0.slo_sli_condition",
384+
"trigger_conditions.0.slo_burn_rate_condition",
385+
}
386+
logStaticConditionCriticalOrWarningAtleastOneKeys = []string{
387+
"trigger_conditions.0.logs_static_condition.0.warning",
388+
"trigger_conditions.0.logs_static_condition.0.critical",
389+
}
390+
metricsStaticConditionCriticalOrWarningAtleastOneKeys = []string{
391+
"trigger_conditions.0.metrics_static_condition.0.warning",
392+
"trigger_conditions.0.metrics_static_condition.0.critical",
393+
}
394+
logsOutlierConditionCriticalOrWarningAtleastOneKeys = []string{
395+
"trigger_conditions.0.logs_outlier_condition.0.warning",
396+
"trigger_conditions.0.logs_outlier_condition.0.critical",
397+
}
398+
metricsOutlierConditionCriticalOrWarningAtleastOneKeys = []string{
399+
"trigger_conditions.0.metrics_outlier_condition.0.warning",
400+
"trigger_conditions.0.metrics_outlier_condition.0.critical",
401+
}
402+
sloSLIConditionCriticalOrWarningAtleastOneKeys = []string{
403+
"trigger_conditions.0.slo_sli_condition.0.warning",
404+
"trigger_conditions.0.slo_sli_condition.0.critical",
405+
}
406+
sloBurnRateConditionCriticalOrWarningAtleastOneKeys = []string{
407+
"trigger_conditions.0.slo_burn_rate_condition.0.warning",
408+
"trigger_conditions.0.slo_burn_rate_condition.0.critical",
409+
}
410+
)
411+
392412
// Trigger Condition schemas
393413
var logsStaticTriggerConditionSchema = map[string]*schema.Schema{
394414
"field": {
@@ -406,7 +426,7 @@ var logsStaticTriggerConditionSchema = map[string]*schema.Schema{
406426
"threshold_type": &thresholdTypeSchema,
407427
"resolution_window": &resolutionWindowSchema,
408428
}),
409-
}, criticalOrWarningAtleastOneKeys),
429+
}, logStaticConditionCriticalOrWarningAtleastOneKeys),
410430
"warning": nestedWithAtleastOneOfKeys(true, schemaMap{
411431
"time_range": &timeRangeSchema,
412432
"alert": nested(false, schemaMap{
@@ -418,7 +438,7 @@ var logsStaticTriggerConditionSchema = map[string]*schema.Schema{
418438
"threshold_type": &thresholdTypeSchema,
419439
"resolution_window": &resolutionWindowSchema,
420440
}),
421-
}, criticalOrWarningAtleastOneKeys),
441+
}, logStaticConditionCriticalOrWarningAtleastOneKeys),
422442
}
423443

424444
var metricsStaticTriggerConditionSchema = map[string]*schema.Schema{
@@ -434,7 +454,7 @@ var metricsStaticTriggerConditionSchema = map[string]*schema.Schema{
434454
"threshold_type": &thresholdTypeSchema,
435455
"occurrence_type": &occurrenceTypeOptSchema,
436456
}),
437-
}, criticalOrWarningAtleastOneKeys),
457+
}, metricsStaticConditionCriticalOrWarningAtleastOneKeys),
438458
"warning": nestedWithAtleastOneOfKeys(true, schemaMap{
439459
"time_range": &timeRangeSchema,
440460
"occurrence_type": &occurrenceTypeSchema,
@@ -447,7 +467,7 @@ var metricsStaticTriggerConditionSchema = map[string]*schema.Schema{
447467
"threshold_type": &thresholdTypeSchema,
448468
"occurrence_type": &occurrenceTypeOptSchema,
449469
}),
450-
}, criticalOrWarningAtleastOneKeys),
470+
}, metricsStaticConditionCriticalOrWarningAtleastOneKeys),
451471
}
452472

453473
var logsOutlierTriggerConditionSchema = map[string]*schema.Schema{
@@ -464,12 +484,12 @@ var logsOutlierTriggerConditionSchema = map[string]*schema.Schema{
464484
"window": &windowSchema,
465485
"consecutive": &consecutiveSchema,
466486
"threshold": &thresholdSchema,
467-
}, criticalOrWarningAtleastOneKeys),
487+
}, logsOutlierConditionCriticalOrWarningAtleastOneKeys),
468488
"warning": nestedWithAtleastOneOfKeys(true, schemaMap{
469489
"window": &windowSchema,
470490
"consecutive": &consecutiveSchema,
471491
"threshold": &thresholdSchema,
472-
}, criticalOrWarningAtleastOneKeys),
492+
}, logsOutlierConditionCriticalOrWarningAtleastOneKeys),
473493
}
474494

475495
var metricsOutlierTriggerConditionSchema = map[string]*schema.Schema{
@@ -481,11 +501,11 @@ var metricsOutlierTriggerConditionSchema = map[string]*schema.Schema{
481501
"critical": nestedWithAtleastOneOfKeys(true, schemaMap{
482502
"baseline_window": &baselineWindowSchema,
483503
"threshold": &thresholdSchema,
484-
}, criticalOrWarningAtleastOneKeys),
504+
}, metricsOutlierConditionCriticalOrWarningAtleastOneKeys),
485505
"warning": nestedWithAtleastOneOfKeys(true, schemaMap{
486506
"baseline_window": &baselineWindowSchema,
487507
"threshold": &thresholdSchema,
488-
}, criticalOrWarningAtleastOneKeys),
508+
}, metricsOutlierConditionCriticalOrWarningAtleastOneKeys),
489509
}
490510

491511
var logsMissingDataTriggerConditionSchema = map[string]*schema.Schema{
@@ -508,14 +528,14 @@ var sloSLITriggerConditionSchema = map[string]*schema.Schema{
508528
Required: true,
509529
ValidateFunc: validation.FloatBetween(0, 100),
510530
},
511-
}, criticalOrWarningAtleastOneKeys),
531+
}, sloSLIConditionCriticalOrWarningAtleastOneKeys),
512532
"warning": nestedWithAtleastOneOfKeys(true, schemaMap{
513533
"sli_threshold": {
514534
Type: schema.TypeFloat,
515535
Required: true,
516536
ValidateFunc: validation.FloatBetween(0, 100),
517537
},
518-
}, criticalOrWarningAtleastOneKeys),
538+
}, sloSLIConditionCriticalOrWarningAtleastOneKeys),
519539
}
520540

521541
var sloBurnRateTriggerConditionSchema = map[string]*schema.Schema{
@@ -526,15 +546,15 @@ var sloBurnRateTriggerConditionSchema = map[string]*schema.Schema{
526546
Required: true,
527547
ValidateFunc: validation.FloatAtLeast(0),
528548
},
529-
}, criticalOrWarningAtleastOneKeys),
549+
}, sloBurnRateConditionCriticalOrWarningAtleastOneKeys),
530550
"warning": nestedWithAtleastOneOfKeys(true, schemaMap{
531551
"time_range": &timeRangeSchema,
532552
"burn_rate_threshold": {
533553
Type: schema.TypeFloat,
534554
Required: true,
535555
ValidateFunc: validation.FloatAtLeast(0),
536556
},
537-
}, criticalOrWarningAtleastOneKeys),
557+
}, sloBurnRateConditionCriticalOrWarningAtleastOneKeys),
538558
}
539559

540560
var occurrenceTypeSchema = schema.Schema{

sumologic/resource_sumologic_monitors_library_monitor_test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestSumologicMonitorsLibraryMonitor_conversionsToFromTriggerConditionsShoul
8181
}
8282
}
8383

84-
func TestAccSumologicMonitorsLibraryMonitor_schemaValidations(t *testing.T) {
84+
func TestAccSumologicMonitorsLibraryMonitor_schemaTriggerValidations(t *testing.T) {
8585
var monitorsLibraryMonitor MonitorsLibraryMonitor
8686
config := `
8787
resource "sumologic_monitor" "test" {
@@ -104,8 +104,11 @@ func TestAccSumologicMonitorsLibraryMonitor_schemaValidations(t *testing.T) {
104104
},
105105
},
106106
})
107+
}
107108

108-
for _, monitorConfig := range allInvalidMonitors {
109+
func TestAccSumologicMonitorsLibraryMonitor_schemaTriggerConditionValidations(t *testing.T) {
110+
var monitorsLibraryMonitor MonitorsLibraryMonitor
111+
for _, monitorConfig := range allInvalidTriggerConditionMonitorResources {
109112
testNameSuffix := acctest.RandString(16)
110113

111114
testName := "terraform_test_invalid_monitor_" + testNameSuffix
@@ -1044,7 +1047,7 @@ func exampleMonitorWithTriggerCondition(
10441047
trigger string,
10451048
triggerTys []string) string {
10461049
triggerTysStr := `"` + strings.Join(triggerTys, `","`) + `"`
1047-
return fmt.Sprintf(`
1050+
var resourceText = fmt.Sprintf(`
10481051
resource "sumologic_monitor" "test" {
10491052
name = "%s"
10501053
description = "terraform_test_monitor_description"
@@ -1071,6 +1074,7 @@ resource "sumologic_monitor" "test" {
10711074
}
10721075
playbook = "This is a test playbook"
10731076
}`, testName, monitorType, query, trigger, triggerTysStr)
1077+
return resourceText
10741078
}
10751079

10761080
var exampleLogsStaticTriggerConditionBlock = `
@@ -1387,7 +1391,7 @@ func testAccCheckMonitorsLibraryMonitorFGPBackend(
13871391
}
13881392
}
13891393

1390-
var allInvalidMonitors = []func(testName string) string{
1394+
var allInvalidTriggerConditionMonitorResources = []func(testName string) string{
13911395
invalidExampleWithNoTriggerCondition,
13921396
invalidExampleWithEmptyLogStaticTriggerCondition,
13931397
invalidExampleWithEmptyMetricsStaticTriggerCondition,

0 commit comments

Comments
 (0)