@@ -10,6 +10,7 @@ import (
1010
1111const fieldNameWindowBasedEvaluation = `window_based_evaluation`
1212const fieldNameRequestBasedEvaluation = `request_based_evaluation`
13+ const fieldNameMonitorBasedEvaluation = `monitor_based_evaluation`
1314const sloContentTypeString = "Slo"
1415
1516func resourceSumologicSLO () * schema.Resource {
@@ -116,6 +117,41 @@ func resourceSumologicSLO() *schema.Resource {
116117 },
117118 }
118119
120+ triggerTypeSchema := & schema.Schema {
121+ Type : schema .TypeString ,
122+ ValidateFunc : validation .StringInSlice ([]string {
123+ "Critical" , "Warning" , "MissingData" ,
124+ }, false ),
125+ }
126+
127+ monitorTriggerSchema := & schema.Resource {
128+ Schema : map [string ]* schema.Schema {
129+ "monitor_id" : {
130+ Type : schema .TypeString ,
131+ Required : true ,
132+ },
133+ "trigger_types" : {
134+ Type : schema .TypeList ,
135+ MinItems : 1 ,
136+ MaxItems : 1 ,
137+ Elem : triggerTypeSchema ,
138+ Required : true ,
139+ },
140+ },
141+ }
142+
143+ monitorBasedIndicatorSchema := & schema.Resource {
144+ Schema : map [string ]* schema.Schema {
145+ "monitor_triggers" : {
146+ Type : schema .TypeList ,
147+ MinItems : 1 ,
148+ MaxItems : 1 ,
149+ Required : true ,
150+ Elem : monitorTriggerSchema ,
151+ },
152+ },
153+ }
154+
119155 return & schema.Resource {
120156 Create : resourceSumologicSLOCreate ,
121157 Read : resourceSLORead ,
@@ -231,6 +267,12 @@ func resourceSumologicSLO() *schema.Resource {
231267 Optional : true ,
232268 Elem : requestBasedIndicatorSchema ,
233269 },
270+ fieldNameMonitorBasedEvaluation : {
271+ Type : schema .TypeList ,
272+ MaxItems : 1 ,
273+ Optional : true ,
274+ Elem : monitorBasedIndicatorSchema ,
275+ },
234276 },
235277 },
236278 },
@@ -386,6 +428,8 @@ func flattenSLOIndicator(ind SLOIndicator) (map[string]interface{}, error) {
386428 return flattenRequestIndicator (ind )
387429 case "Window" :
388430 return flattenWindowIndicator (ind )
431+ case "Monitor" :
432+ return flattenMonitorIndicator (ind )
389433 default :
390434 return nil , fmt .Errorf ("unhandled indicator type found : %s" , ind .EvaluationType )
391435 }
@@ -410,6 +454,29 @@ func flattenRequestIndicator(ind SLOIndicator) (map[string]interface{}, error) {
410454 }, nil
411455}
412456
457+ func flattenMonitorIndicator (ind SLOIndicator ) (map [string ]interface {}, error ) {
458+ monitorIndicator := map [string ]interface {}{}
459+ monitorTriggers , err := flattenMonitorTriggers (ind .MonitorTriggers )
460+ if err != nil {
461+ return nil , err
462+ }
463+ monitorIndicator ["monitor_triggers" ] = monitorTriggers
464+ return map [string ]interface {}{
465+ fieldNameMonitorBasedEvaluation : []interface {}{monitorIndicator },
466+ }, nil
467+ }
468+
469+ func flattenMonitorTriggers (triggers []MonitorTrigger ) ([]interface {}, error ) {
470+ var triggerList []interface {}
471+ for _ , trigger := range triggers {
472+ queryMap := map [string ]interface {}{}
473+ queryMap ["monitor_id" ] = trigger .MonitorId
474+ queryMap ["trigger_types" ] = trigger .TriggerTypes
475+ triggerList = append (triggerList , queryMap )
476+ }
477+ return triggerList , nil
478+ }
479+
413480func flattenWindowIndicator (ind SLOIndicator ) (map [string ]interface {}, error ) {
414481 windowIndicator := map [string ]interface {}{}
415482 windowIndicator ["query_type" ] = ind .QueryType
@@ -582,7 +649,34 @@ func getSLOIndicator(d *schema.ResourceData) (*SLOIndicator, error) {
582649 }, nil
583650 }
584651
585- return nil , fmt .Errorf ("can't find indicator in resource, valid types are '%s' and '%s'" , fieldNameRequestBasedEvaluation , fieldNameWindowBasedEvaluation )
652+ if indicatorWrapperDict [fieldNameMonitorBasedEvaluation ] != nil &&
653+ len (indicatorWrapperDict [fieldNameMonitorBasedEvaluation ].([]interface {})) > 0 {
654+ indicatorDictList := indicatorWrapperDict [fieldNameMonitorBasedEvaluation ].([]interface {})
655+ var monitorTriggers []MonitorTrigger
656+ for _ , indicatorDictElem := range indicatorDictList {
657+ indicatorDictElemMapped := indicatorDictElem .(map [string ]interface {})
658+ monitorTriggersMappedArray := indicatorDictElemMapped ["monitor_triggers" ].([]interface {})
659+ for _ , monitorTriggersElem := range monitorTriggersMappedArray {
660+ monitorIdResult := monitorTriggersElem .(map [string ]interface {})["monitor_id" ].(string )
661+ triggerTypes := monitorTriggersElem .(map [string ]interface {})["trigger_types" ].([]interface {})
662+ var triggerTypesResult []string
663+ for _ , triggerType := range triggerTypes {
664+ triggerTypesResult = append (triggerTypesResult , triggerType .(string ))
665+ }
666+ monitorTriggers = append (monitorTriggers , MonitorTrigger {
667+ MonitorId : monitorIdResult ,
668+ TriggerTypes : triggerTypesResult ,
669+ })
670+ }
671+ }
672+
673+ return & SLOIndicator {
674+ EvaluationType : "Monitor" ,
675+ MonitorTriggers : monitorTriggers ,
676+ }, nil
677+ }
678+
679+ return nil , fmt .Errorf ("can't find indicator in resource, valid types are '%s', '%s' and '%s'" , fieldNameRequestBasedEvaluation , fieldNameWindowBasedEvaluation , fieldNameMonitorBasedEvaluation )
586680}
587681
588682func GetSLOIndicatorQueries (queriesRaw []interface {}) []SLIQueryGroup {
0 commit comments