@@ -99,16 +99,41 @@ func ResourceTencentCloudClsAlarm() *schema.Resource {
99
99
},
100
100
101
101
"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." ,
105
106
},
106
107
107
108
"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
+ },
112
137
},
113
138
114
139
"trigger_count" : {
@@ -287,15 +312,34 @@ func resourceTencentCloudClsAlarmCreate(d *schema.ResourceData, meta interface{}
287
312
request .MonitorTime = & monitorTime
288
313
}
289
314
290
- if v , ok := d .GetOk ("condition" ); ok {
315
+ var changeCondition bool
316
+ if v , ok := d .GetOk ("condition" ); ok && v .(string ) != "" {
291
317
request .Condition = helper .String (v .(string ))
292
318
request .AlarmLevel = helper .IntUint64 (0 )
319
+ changeCondition = true
293
320
}
294
321
295
- if v , ok := d .GetOkExists ("alarm_level" ); ok {
322
+ if v , ok := d .GetOkExists ("alarm_level" ); ok && changeCondition {
296
323
request .AlarmLevel = helper .IntUint64 (v .(int ))
297
324
}
298
325
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
+
299
343
if v , ok := d .GetOkExists ("trigger_count" ); ok {
300
344
request .TriggerCount = helper .IntInt64 (v .(int ))
301
345
}
@@ -486,12 +530,29 @@ func resourceTencentCloudClsAlarmRead(d *schema.ResourceData, meta interface{})
486
530
_ = d .Set ("monitor_time" , []interface {}{monitorTimeMap })
487
531
}
488
532
489
- if alarm .Condition != nil {
533
+ if alarm .Condition != nil && * alarm . Condition != "" {
490
534
_ = d .Set ("condition" , alarm .Condition )
535
+ if alarm .AlarmLevel != nil {
536
+ _ = d .Set ("alarm_level" , alarm .AlarmLevel )
537
+ }
491
538
}
492
539
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 )
495
556
}
496
557
497
558
if alarm .TriggerCount != nil {
@@ -597,7 +658,7 @@ func resourceTencentCloudClsAlarmUpdate(d *schema.ResourceData, meta interface{}
597
658
request .AlarmId = & alarmId
598
659
mutableArgs := []string {
599
660
"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" ,
601
662
"status" , "message_template" , "call_back" , "analysis" ,
602
663
}
603
664
@@ -662,15 +723,34 @@ func resourceTencentCloudClsAlarmUpdate(d *schema.ResourceData, meta interface{}
662
723
request .MonitorTime = & monitorTime
663
724
}
664
725
665
- if v , ok := d .GetOk ("condition" ); ok {
726
+ var changeCondition bool
727
+ if v , ok := d .GetOk ("condition" ); ok && v .(string ) != "" {
666
728
request .Condition = helper .String (v .(string ))
667
729
request .AlarmLevel = helper .IntUint64 (0 )
730
+ changeCondition = true
668
731
}
669
732
670
- if v , ok := d .GetOkExists ("alarm_level" ); ok {
733
+ if v , ok := d .GetOkExists ("alarm_level" ); ok && changeCondition {
671
734
request .AlarmLevel = helper .IntUint64 (v .(int ))
672
735
}
673
736
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
+
674
754
if v , ok := d .GetOkExists ("trigger_count" ); ok {
675
755
request .TriggerCount = helper .IntInt64 (v .(int ))
676
756
}
0 commit comments