@@ -146,6 +146,7 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource {
146146 Elem : & schema.Resource {
147147 Schema : logsStaticTriggerConditionSchema ,
148148 },
149+ AtLeastOneOf : triggerConditionsAtleatOneKey ,
149150 },
150151 "metrics_static_condition" : {
151152 Type : schema .TypeList ,
@@ -371,13 +372,50 @@ func resourceSumologicMonitorsLibraryMonitor() *schema.Resource {
371372 }
372373}
373374
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+
374412// Trigger Condition schemas
375413var logsStaticTriggerConditionSchema = map [string ]* schema.Schema {
376414 "field" : {
377415 Type : schema .TypeString ,
378416 Optional : true ,
379417 },
380- "critical" : nested (true , schemaMap {
418+ "critical" : nestedWithAtleastOneOfKeys (true , schemaMap {
381419 "time_range" : & timeRangeSchema ,
382420 "alert" : nested (false , schemaMap {
383421 "threshold" : & thresholdSchema ,
@@ -388,8 +426,8 @@ var logsStaticTriggerConditionSchema = map[string]*schema.Schema{
388426 "threshold_type" : & thresholdTypeSchema ,
389427 "resolution_window" : & resolutionWindowSchema ,
390428 }),
391- }),
392- "warning" : nested (true , schemaMap {
429+ }, logStaticConditionCriticalOrWarningAtleastOneKeys ),
430+ "warning" : nestedWithAtleastOneOfKeys (true , schemaMap {
393431 "time_range" : & timeRangeSchema ,
394432 "alert" : nested (false , schemaMap {
395433 "threshold" : & thresholdSchema ,
@@ -400,11 +438,11 @@ var logsStaticTriggerConditionSchema = map[string]*schema.Schema{
400438 "threshold_type" : & thresholdTypeSchema ,
401439 "resolution_window" : & resolutionWindowSchema ,
402440 }),
403- }),
441+ }, logStaticConditionCriticalOrWarningAtleastOneKeys ),
404442}
405443
406444var metricsStaticTriggerConditionSchema = map [string ]* schema.Schema {
407- "critical" : nested (true , schemaMap {
445+ "critical" : nestedWithAtleastOneOfKeys (true , schemaMap {
408446 "time_range" : & timeRangeSchema ,
409447 "occurrence_type" : & occurrenceTypeSchema ,
410448 "alert" : nested (false , schemaMap {
@@ -416,8 +454,8 @@ var metricsStaticTriggerConditionSchema = map[string]*schema.Schema{
416454 "threshold_type" : & thresholdTypeSchema ,
417455 "occurrence_type" : & occurrenceTypeOptSchema ,
418456 }),
419- }),
420- "warning" : nested (true , schemaMap {
457+ }, metricsStaticConditionCriticalOrWarningAtleastOneKeys ),
458+ "warning" : nestedWithAtleastOneOfKeys (true , schemaMap {
421459 "time_range" : & timeRangeSchema ,
422460 "occurrence_type" : & occurrenceTypeSchema ,
423461 "alert" : nested (false , schemaMap {
@@ -429,7 +467,7 @@ var metricsStaticTriggerConditionSchema = map[string]*schema.Schema{
429467 "threshold_type" : & thresholdTypeSchema ,
430468 "occurrence_type" : & occurrenceTypeOptSchema ,
431469 }),
432- }),
470+ }, metricsStaticConditionCriticalOrWarningAtleastOneKeys ),
433471}
434472
435473var logsOutlierTriggerConditionSchema = map [string ]* schema.Schema {
@@ -442,16 +480,16 @@ var logsOutlierTriggerConditionSchema = map[string]*schema.Schema{
442480 Optional : true ,
443481 ValidateFunc : validation .StringInSlice ([]string {"Both" , "Up" , "Down" }, false ),
444482 },
445- "critical" : nested (true , schemaMap {
483+ "critical" : nestedWithAtleastOneOfKeys (true , schemaMap {
446484 "window" : & windowSchema ,
447485 "consecutive" : & consecutiveSchema ,
448486 "threshold" : & thresholdSchema ,
449- }),
450- "warning" : nested (true , schemaMap {
487+ }, logsOutlierConditionCriticalOrWarningAtleastOneKeys ),
488+ "warning" : nestedWithAtleastOneOfKeys (true , schemaMap {
451489 "window" : & windowSchema ,
452490 "consecutive" : & consecutiveSchema ,
453491 "threshold" : & thresholdSchema ,
454- }),
492+ }, logsOutlierConditionCriticalOrWarningAtleastOneKeys ),
455493}
456494
457495var metricsOutlierTriggerConditionSchema = map [string ]* schema.Schema {
@@ -460,14 +498,14 @@ var metricsOutlierTriggerConditionSchema = map[string]*schema.Schema{
460498 Optional : true ,
461499 ValidateFunc : validation .StringInSlice ([]string {"Both" , "Up" , "Down" }, false ),
462500 },
463- "critical" : nested (true , schemaMap {
501+ "critical" : nestedWithAtleastOneOfKeys (true , schemaMap {
464502 "baseline_window" : & baselineWindowSchema ,
465503 "threshold" : & thresholdSchema ,
466- }),
467- "warning" : nested (true , schemaMap {
504+ }, metricsOutlierConditionCriticalOrWarningAtleastOneKeys ),
505+ "warning" : nestedWithAtleastOneOfKeys (true , schemaMap {
468506 "baseline_window" : & baselineWindowSchema ,
469507 "threshold" : & thresholdSchema ,
470- }),
508+ }, metricsOutlierConditionCriticalOrWarningAtleastOneKeys ),
471509}
472510
473511var logsMissingDataTriggerConditionSchema = map [string ]* schema.Schema {
@@ -484,39 +522,39 @@ var metricsMissingDataTriggerConditionSchema = map[string]*schema.Schema{
484522}
485523
486524var sloSLITriggerConditionSchema = map [string ]* schema.Schema {
487- "critical" : nested (true , schemaMap {
525+ "critical" : nestedWithAtleastOneOfKeys (true , schemaMap {
488526 "sli_threshold" : {
489527 Type : schema .TypeFloat ,
490528 Required : true ,
491529 ValidateFunc : validation .FloatBetween (0 , 100 ),
492530 },
493- }),
494- "warning" : nested (true , schemaMap {
531+ }, sloSLIConditionCriticalOrWarningAtleastOneKeys ),
532+ "warning" : nestedWithAtleastOneOfKeys (true , schemaMap {
495533 "sli_threshold" : {
496534 Type : schema .TypeFloat ,
497535 Required : true ,
498536 ValidateFunc : validation .FloatBetween (0 , 100 ),
499537 },
500- }),
538+ }, sloSLIConditionCriticalOrWarningAtleastOneKeys ),
501539}
502540
503541var sloBurnRateTriggerConditionSchema = map [string ]* schema.Schema {
504- "critical" : nested (true , schemaMap {
542+ "critical" : nestedWithAtleastOneOfKeys (true , schemaMap {
505543 "time_range" : & timeRangeSchema ,
506544 "burn_rate_threshold" : {
507545 Type : schema .TypeFloat ,
508546 Required : true ,
509547 ValidateFunc : validation .FloatAtLeast (0 ),
510548 },
511- }),
512- "warning" : nested (true , schemaMap {
549+ }, sloBurnRateConditionCriticalOrWarningAtleastOneKeys ),
550+ "warning" : nestedWithAtleastOneOfKeys (true , schemaMap {
513551 "time_range" : & timeRangeSchema ,
514552 "burn_rate_threshold" : {
515553 Type : schema .TypeFloat ,
516554 Required : true ,
517555 ValidateFunc : validation .FloatAtLeast (0 ),
518556 },
519- }),
557+ }, sloBurnRateConditionCriticalOrWarningAtleastOneKeys ),
520558}
521559
522560var occurrenceTypeSchema = schema.Schema {
@@ -1430,6 +1468,26 @@ func nested(optional bool, sch map[string]*schema.Schema) *schema.Schema {
14301468 }
14311469}
14321470
1471+ func nestedWithAtleastOneOfKeys (optional bool , sch map [string ]* schema.Schema , atleastOneOfKeys []string ) * schema.Schema {
1472+ if optional {
1473+ return & schema.Schema {
1474+ Type : schema .TypeList ,
1475+ Optional : true ,
1476+ MaxItems : 1 ,
1477+ Elem : toResource (sch ),
1478+ AtLeastOneOf : atleastOneOfKeys ,
1479+ }
1480+ } else {
1481+ return & schema.Schema {
1482+ Type : schema .TypeList ,
1483+ Required : true ,
1484+ MaxItems : 1 ,
1485+ Elem : toResource (sch ),
1486+ AtLeastOneOf : atleastOneOfKeys ,
1487+ }
1488+ }
1489+ }
1490+
14331491func (condition * TriggerCondition ) readFrom (block map [string ]interface {}) {
14341492 for k , v := range block {
14351493 switch k {
0 commit comments