@@ -99,16 +99,41 @@ func ResourceTencentCloudClsAlarm() *schema.Resource {
9999 },
100100
101101 "condition" : {
102- Required : true ,
103- Type : schema .TypeString ,
104- Description : "triggering conditions." ,
102+ Optional : true ,
103+ Type : schema .TypeString ,
104+ ExactlyOneOf : []string {"multi_conditions" },
105+ Description : "Trigger condition." ,
105106 },
106107
107108 "alarm_level" : {
108- Optional : true ,
109- Computed : true ,
110- Type : schema .TypeInt ,
111- Description : "Alarm level. 0: Warning; 1: Info; 2: Critical. Default is 0." ,
109+ Optional : true ,
110+ Computed : true ,
111+ Type : schema .TypeInt ,
112+ ConflictsWith : []string {"multi_conditions" },
113+ RequiredWith : []string {"condition" },
114+ Description : "Alarm level. 0: Warning; 1: Info; 2: Critical. Default is 0." ,
115+ },
116+
117+ "multi_conditions" : {
118+ Optional : true ,
119+ Type : schema .TypeList ,
120+ ExactlyOneOf : []string {"condition" },
121+ Description : "Multiple triggering conditions." ,
122+ Elem : & schema.Resource {
123+ Schema : map [string ]* schema.Schema {
124+ "condition" : {
125+ Type : schema .TypeString ,
126+ Optional : true ,
127+ Description : "Trigger condition." ,
128+ },
129+ "alarm_level" : {
130+ Type : schema .TypeInt ,
131+ Optional : true ,
132+ Computed : true ,
133+ Description : "Alarm level. 0: Warning; 1: Info; 2: Critical. Default is 0." ,
134+ },
135+ },
136+ },
112137 },
113138
114139 "trigger_count" : {
@@ -287,15 +312,34 @@ func resourceTencentCloudClsAlarmCreate(d *schema.ResourceData, meta interface{}
287312 request .MonitorTime = & monitorTime
288313 }
289314
290- if v , ok := d .GetOk ("condition" ); ok {
315+ var changeCondition bool
316+ if v , ok := d .GetOk ("condition" ); ok && v .(string ) != "" {
291317 request .Condition = helper .String (v .(string ))
292318 request .AlarmLevel = helper .IntUint64 (0 )
319+ changeCondition = true
293320 }
294321
295- if v , ok := d .GetOkExists ("alarm_level" ); ok {
322+ if v , ok := d .GetOkExists ("alarm_level" ); ok && changeCondition {
296323 request .AlarmLevel = helper .IntUint64 (v .(int ))
297324 }
298325
326+ if v , ok := d .GetOk ("multi_conditions" ); ok {
327+ for _ , item := range v .([]interface {}) {
328+ dMap := item .(map [string ]interface {})
329+ multiCondition := cls.MultiCondition {}
330+ if v , ok := dMap ["condition" ]; ok {
331+ multiCondition .Condition = helper .String (v .(string ))
332+ multiCondition .AlarmLevel = helper .IntUint64 (0 )
333+ }
334+
335+ if v , ok := dMap ["alarm_level" ]; ok {
336+ multiCondition .AlarmLevel = helper .IntUint64 (v .(int ))
337+ }
338+
339+ request .MultiConditions = append (request .MultiConditions , & multiCondition )
340+ }
341+ }
342+
299343 if v , ok := d .GetOkExists ("trigger_count" ); ok {
300344 request .TriggerCount = helper .IntInt64 (v .(int ))
301345 }
@@ -486,12 +530,29 @@ func resourceTencentCloudClsAlarmRead(d *schema.ResourceData, meta interface{})
486530 _ = d .Set ("monitor_time" , []interface {}{monitorTimeMap })
487531 }
488532
489- if alarm .Condition != nil {
533+ if alarm .Condition != nil && * alarm . Condition != "" {
490534 _ = d .Set ("condition" , alarm .Condition )
535+ if alarm .AlarmLevel != nil {
536+ _ = d .Set ("alarm_level" , alarm .AlarmLevel )
537+ }
491538 }
492539
493- if alarm .AlarmLevel != nil {
494- _ = d .Set ("alarm_level" , alarm .AlarmLevel )
540+ if alarm .MultiConditions != nil {
541+ tmpList := make ([]map [string ]interface {}, 0 )
542+ for _ , item := range alarm .MultiConditions {
543+ dMap := make (map [string ]interface {})
544+ if item .Condition != nil {
545+ dMap ["condition" ] = * item .Condition
546+ }
547+
548+ if item .AlarmLevel != nil {
549+ dMap ["alarm_level" ] = * item .AlarmLevel
550+ }
551+
552+ tmpList = append (tmpList , dMap )
553+ }
554+
555+ _ = d .Set ("multi_conditions" , tmpList )
495556 }
496557
497558 if alarm .TriggerCount != nil {
@@ -597,7 +658,7 @@ func resourceTencentCloudClsAlarmUpdate(d *schema.ResourceData, meta interface{}
597658 request .AlarmId = & alarmId
598659 mutableArgs := []string {
599660 "name" , "alarm_targets" , "monitor_time" , "condition" , "alarm_level" ,
600- "trigger_count" , "alarm_period" , "alarm_notice_ids" ,
661+ "multi_conditions" , " trigger_count" , "alarm_period" , "alarm_notice_ids" ,
601662 "status" , "message_template" , "call_back" , "analysis" ,
602663 }
603664
@@ -662,15 +723,34 @@ func resourceTencentCloudClsAlarmUpdate(d *schema.ResourceData, meta interface{}
662723 request .MonitorTime = & monitorTime
663724 }
664725
665- if v , ok := d .GetOk ("condition" ); ok {
726+ var changeCondition bool
727+ if v , ok := d .GetOk ("condition" ); ok && v .(string ) != "" {
666728 request .Condition = helper .String (v .(string ))
667729 request .AlarmLevel = helper .IntUint64 (0 )
730+ changeCondition = true
668731 }
669732
670- if v , ok := d .GetOkExists ("alarm_level" ); ok {
733+ if v , ok := d .GetOkExists ("alarm_level" ); ok && changeCondition {
671734 request .AlarmLevel = helper .IntUint64 (v .(int ))
672735 }
673736
737+ if v , ok := d .GetOk ("multi_conditions" ); ok {
738+ for _ , item := range v .([]interface {}) {
739+ dMap := item .(map [string ]interface {})
740+ multiCondition := cls.MultiCondition {}
741+ if v , ok := dMap ["condition" ]; ok {
742+ multiCondition .Condition = helper .String (v .(string ))
743+ multiCondition .AlarmLevel = helper .IntUint64 (0 )
744+ }
745+
746+ if v , ok := dMap ["alarm_level" ]; ok {
747+ multiCondition .AlarmLevel = helper .IntUint64 (v .(int ))
748+ }
749+
750+ request .MultiConditions = append (request .MultiConditions , & multiCondition )
751+ }
752+ }
753+
674754 if v , ok := d .GetOkExists ("trigger_count" ); ok {
675755 request .TriggerCount = helper .IntInt64 (v .(int ))
676756 }
0 commit comments