@@ -556,57 +556,36 @@ var sloSLITriggerConditionSchema = map[string]*schema.Schema{
556556
557557var sloBurnRateTriggerConditionSchema = map [string ]* schema.Schema {
558558 "critical" : nestedWithAtleastOneOfKeys (true , schemaMap {
559- "time_range" : getSloBurnRateTimeRangeSchema ("critical" ),
560- "burn_rate_threshold" : {
561- Type : schema .TypeFloat ,
562- Optional : true ,
563- ValidateFunc : validation .FloatAtLeast (0 ),
564- RequiredWith : []string {"trigger_conditions.0.slo_burn_rate_condition.0.critical.0.time_range" },
565- ConflictsWith : []string {"trigger_conditions.0.slo_burn_rate_condition.0.critical.0.burn_rate" },
566- },
567- "burn_rate" : {
568- Optional : true ,
569- Type : schema .TypeList ,
570- ConflictsWith : []string {"trigger_conditions.0.slo_burn_rate_condition.0.critical.0.burn_rate_threshold" ,
571- "trigger_conditions.0.slo_burn_rate_condition.0.critical.0.time_range" },
572- Elem : & schema.Resource {
573- Schema : map [string ]* schema.Schema {
574- "burn_rate_threshold" : {
575- Type : schema .TypeFloat ,
576- Required : true ,
577- ValidateFunc : validation .FloatAtLeast (0 ),
578- },
579- "time_range" : & timeRangeSchema ,
580- },
581- },
582- },
559+ "time_range" : getSloBurnRateTimeRangeSchema ("critical" ),
560+ "burn_rate_threshold" : getSloBurnRateThresholdSchema ("critical" ),
561+ "burn_rate" : getBurnRateSchema ("critical" ),
583562 }, sloBurnRateConditionCriticalOrWarningAtleastOneKeys ),
584563 "warning" : nestedWithAtleastOneOfKeys (true , schemaMap {
585- "time_range" : getSloBurnRateTimeRangeSchema ("warning" ),
586- "burn_rate_threshold" : {
587- Type : schema .TypeFloat ,
588- Optional : true ,
589- ValidateFunc : validation .FloatAtLeast (0 ),
590- RequiredWith : []string {"trigger_conditions.0.slo_burn_rate_condition.0.warning.0.time_range" },
591- ConflictsWith : []string {"trigger_conditions.0.slo_burn_rate_condition.0.warning.0.burn_rate" },
592- },
593- "burn_rate" : {
594- Optional : true ,
595- Type : schema .TypeList ,
596- ConflictsWith : []string {"trigger_conditions.0.slo_burn_rate_condition.0.warning.0.burn_rate_threshold" ,
597- "trigger_conditions.0.slo_burn_rate_condition.0.warning.0.time_range" },
598- Elem : & schema.Resource {
599- Schema : map [string ]* schema.Schema {
600- "burn_rate_threshold" : {
601- Type : schema .TypeFloat ,
602- Required : true ,
603- ValidateFunc : validation .FloatAtLeast (0 ),
604- },
605- "time_range" : & timeRangeSchema ,
564+ "time_range" : getSloBurnRateTimeRangeSchema ("warning" ),
565+ "burn_rate_threshold" : getSloBurnRateThresholdSchema ("warning" ),
566+ "burn_rate" : getBurnRateSchema ("warning" ),
567+ }, sloBurnRateConditionCriticalOrWarningAtleastOneKeys ),
568+ }
569+
570+ func getBurnRateSchema (triggerType string ) * schema.Schema {
571+ burnRateThresholdConflict := fmt .Sprintf ("trigger_conditions.0.slo_burn_rate_condition.0.%s.0.burn_rate_threshold" , triggerType )
572+ timeRangeConflict := fmt .Sprintf ("trigger_conditions.0.slo_burn_rate_condition.0.%s.0.time_range" , triggerType )
573+
574+ return & schema.Schema {
575+ Optional : true ,
576+ Type : schema .TypeList ,
577+ ConflictsWith : []string {burnRateThresholdConflict , timeRangeConflict },
578+ Elem : & schema.Resource {
579+ Schema : map [string ]* schema.Schema {
580+ "burn_rate_threshold" : {
581+ Type : schema .TypeFloat ,
582+ Required : true ,
583+ ValidateFunc : validation .FloatAtLeast (0 ),
606584 },
585+ "time_range" : & timeRangeSchema ,
607586 },
608587 },
609- }, sloBurnRateConditionCriticalOrWarningAtleastOneKeys ),
588+ }
610589}
611590
612591var occurrenceTypeSchema = schema.Schema {
@@ -648,23 +627,37 @@ var consecutiveSchema = schema.Schema{
648627var timeRangeSchema = schema.Schema {
649628 Type : schema .TypeString ,
650629 Required : true ,
651- ValidateFunc : validation . StringMatch ( regexp . MustCompile ( `^-?(\d)+[smhd]$` ), "Time range must be in the format '-? \\ d+[smhd]'. Examples: -15m, 1d, etc." ) ,
630+ ValidateFunc : timeRangeValidation ,
652631 DiffSuppressFunc : SuppressEquivalentTimeDiff (false ),
653632}
654633
634+ func getSloBurnRateThresholdSchema (triggerType string ) * schema.Schema {
635+ requiredWith := fmt .Sprintf ("trigger_conditions.0.slo_burn_rate_condition.0.%s.0.time_range" , triggerType )
636+ conflictsWith := fmt .Sprintf ("trigger_conditions.0.slo_burn_rate_condition.0.%s.0.burn_rate" , triggerType )
637+ return & schema.Schema {
638+ Type : schema .TypeFloat ,
639+ Optional : true ,
640+ ValidateFunc : validation .FloatAtLeast (0 ),
641+ RequiredWith : []string {requiredWith },
642+ ConflictsWith : []string {conflictsWith },
643+ }
644+ }
645+
655646func getSloBurnRateTimeRangeSchema (triggerType string ) * schema.Schema {
656647 requiredWith := fmt .Sprintf ("trigger_conditions.0.slo_burn_rate_condition.0.%s.0.burn_rate_threshold" , triggerType )
657648 conflictsWith := fmt .Sprintf ("trigger_conditions.0.slo_burn_rate_condition.0.%s.0.burn_rate" , triggerType )
658649 return & schema.Schema {
659650 Type : schema .TypeString ,
660651 Optional : true ,
661- ValidateFunc : validation . StringMatch ( regexp . MustCompile ( `^-?(\d)+[smhd]$` ), "Time range must be in the format '-? \\ d+[smhd]'. Examples: -15m, 1d, etc." ) ,
652+ ValidateFunc : timeRangeValidation ,
662653 DiffSuppressFunc : SuppressEquivalentTimeDiff (false ),
663654 RequiredWith : []string {requiredWith },
664655 ConflictsWith : []string {conflictsWith },
665656 }
666657}
667658
659+ var timeRangeValidation = validation .StringMatch (regexp .MustCompile (`^-?(\d)+[smhd]$` ), "Time range must be in the format '-?\\ d+[smhd]'. Examples: -15m, 1d, etc." )
660+
668661var resolutionWindowSchema = schema.Schema {
669662 Type : schema .TypeString ,
670663 Optional : true ,
@@ -685,7 +678,7 @@ var thresholdTypeSchema = schema.Schema{
685678
686679func resourceSumologicMonitorsLibraryMonitorCreate (d * schema.ResourceData , meta interface {}) error {
687680 c := meta .(* Client )
688- log . Printf ( "it is create" )
681+
689682 if d .Id () == "" {
690683 monitor := resourceToMonitorsLibraryMonitor (d )
691684 if monitor .ParentID == "" {
@@ -721,7 +714,6 @@ func resourceSumologicMonitorsLibraryMonitorCreate(d *schema.ResourceData, meta
721714
722715func resourceSumologicMonitorsLibraryMonitorRead (d * schema.ResourceData , meta interface {}) error {
723716 c := meta .(* Client )
724- log .Printf ("it is read" )
725717
726718 monitor , err := c .MonitorsRead (d .Id ())
727719 if err != nil {
@@ -1411,32 +1403,10 @@ func jsonToSloBurnRateConditionBlock(conditions []TriggerCondition) map[string]i
14111403 switch condition .TriggerType {
14121404 case "Critical" :
14131405 hasCritical = true
1414- criticalBurnRates := make ([]interface {}, len (condition .BurnRates ))
1415- criticalAlrt ["time_range" ] = condition .TimeRange
1416- criticalAlrt ["burn_rate_threshold" ] = condition .BurnRateThreshold
1417- for i := range condition .BurnRates {
1418- burnRateBlock := map [string ]interface {}{}
1419- burnRateBlock ["burn_rate_threshold" ] = condition .BurnRates [i ].BurnRateThreshold
1420- burnRateBlock ["time_range" ] = condition .BurnRates [i ].TimeRange
1421- criticalBurnRates [i ] = burnRateBlock
1422- }
1423- if len (criticalBurnRates ) > 0 {
1424- criticalAlrt ["burn_rate" ] = criticalBurnRates
1425- }
1406+ criticalAlrt = getAlertBlock (condition )
14261407 case "Warning" :
14271408 hasWarning = true
1428- warningBurnRates := make ([]interface {}, len (condition .BurnRates ))
1429- warningAlrt ["time_range" ] = condition .TimeRange
1430- warningAlrt ["burn_rate_threshold" ] = condition .BurnRateThreshold
1431- for i := range condition .BurnRates {
1432- burnRateBlock := map [string ]interface {}{}
1433- burnRateBlock ["burn_rate_threshold" ] = condition .BurnRates [i ].BurnRateThreshold
1434- burnRateBlock ["time_range" ] = condition .BurnRates [i ].TimeRange
1435- warningBurnRates [i ] = burnRateBlock
1436- }
1437- if len (warningBurnRates ) > 0 {
1438- warningAlrt ["burn_rate" ] = warningBurnRates
1439- }
1409+ warningAlrt = getAlertBlock (condition )
14401410 }
14411411 }
14421412 if ! hasCritical {
@@ -1448,6 +1418,24 @@ func jsonToSloBurnRateConditionBlock(conditions []TriggerCondition) map[string]i
14481418 return block
14491419}
14501420
1421+ func getAlertBlock (condition TriggerCondition ) dict {
1422+ var alert = dict {}
1423+ burnRates := make ([]interface {}, len (condition .BurnRates ))
1424+ alert ["time_range" ] = condition .TimeRange
1425+ alert ["burn_rate_threshold" ] = condition .BurnRateThreshold
1426+
1427+ for i := range condition .BurnRates {
1428+ burnRateBlock := map [string ]interface {}{}
1429+ burnRateBlock ["burn_rate_threshold" ] = condition .BurnRates [i ].BurnRateThreshold
1430+ burnRateBlock ["time_range" ] = condition .BurnRates [i ].TimeRange
1431+ burnRates [i ] = burnRateBlock
1432+ }
1433+ if len (burnRates ) > 0 {
1434+ alert ["burn_rate" ] = burnRates
1435+ }
1436+ return alert
1437+ }
1438+
14511439func jsonToLogsMissingDataConditionBlock (conditions []TriggerCondition ) map [string ]interface {} {
14521440 block := map [string ]interface {}{}
14531441 firstCondition := conditions [0 ]
0 commit comments