Skip to content

Commit 2734ca3

Browse files
committed
add
1 parent 1722c24 commit 2734ca3

5 files changed

+247
-96
lines changed

tencentcloud/services/cls/resource_tc_cls_alarm_notice.go

Lines changed: 173 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,56 +28,62 @@ func ResourceTencentCloudClsAlarmNotice() *schema.Resource {
2828
"name": {
2929
Required: true,
3030
Type: schema.TypeString,
31-
Description: "alarm notice name.",
31+
Description: "Alarm notice name.",
3232
},
3333

3434
"type": {
3535
Required: true,
3636
Type: schema.TypeString,
37-
Description: "notice type.",
37+
Description: "Notice type. Value: Trigger, Recovery, All.",
3838
},
3939

4040
"notice_receivers": {
4141
Optional: true,
4242
Type: schema.TypeList,
43-
Description: "notice receivers.",
43+
Description: "Notice receivers.",
4444
Elem: &schema.Resource{
4545
Schema: map[string]*schema.Schema{
4646
"receiver_type": {
4747
Type: schema.TypeString,
4848
Required: true,
49-
Description: "receiver type, Uin or Group.",
49+
Description: "Receiver type, Uin or Group.",
5050
},
5151
"receiver_ids": {
5252
Type: schema.TypeSet,
5353
Elem: &schema.Schema{
5454
Type: schema.TypeInt,
5555
},
5656
Required: true,
57-
Description: "receiver id.",
57+
Description: "Receiver id list.",
5858
},
5959
"receiver_channels": {
6060
Type: schema.TypeSet,
6161
Elem: &schema.Schema{
6262
Type: schema.TypeString,
6363
},
6464
Required: true,
65-
Description: "receiver channels, Email,Sms,WeChat or Phone.",
65+
Description: "Receiver channels, Value: Email, Sms, WeChat, Phone.",
66+
},
67+
"notice_content_id": {
68+
Type: schema.TypeString,
69+
Optional: true,
70+
Description: "Notice content ID.",
6671
},
6772
"start_time": {
6873
Type: schema.TypeString,
6974
Optional: true,
70-
Description: "start time allowed to receive messages.",
75+
Description: "Start time allowed to receive messages.",
7176
},
7277
"end_time": {
7378
Type: schema.TypeString,
7479
Optional: true,
75-
Description: "end time allowed to receive messages.",
80+
Description: "End time allowed to receive messages.",
7681
},
7782
"index": {
7883
Type: schema.TypeInt,
7984
Optional: true,
80-
Description: "index.",
85+
Computed: true,
86+
Description: "Index. The input parameter is invalid, but the output parameter is valid.",
8187
},
8288
},
8389
},
@@ -86,41 +92,71 @@ func ResourceTencentCloudClsAlarmNotice() *schema.Resource {
8692
"web_callbacks": {
8793
Optional: true,
8894
Type: schema.TypeList,
89-
Description: "callback info.",
95+
Description: "Callback info.",
9096
Elem: &schema.Resource{
9197
Schema: map[string]*schema.Schema{
92-
"url": {
98+
"callback_type": {
9399
Type: schema.TypeString,
94100
Required: true,
95-
Description: "callback url.",
101+
Description: "Callback type, Values: Http, WeCom, DingTalk, Lark.",
96102
},
97-
"callback_type": {
103+
"url": {
98104
Type: schema.TypeString,
99105
Required: true,
100-
Description: "callback type, WeCom or Http.",
106+
Description: "Callback url.",
107+
},
108+
"web_callback_id": {
109+
Type: schema.TypeString,
110+
Optional: true,
111+
Description: "Integration configuration ID.",
101112
},
102113
"method": {
103114
Type: schema.TypeString,
104115
Optional: true,
105116
Description: "Method, POST or PUT.",
106117
},
118+
"notice_content_id": {
119+
Type: schema.TypeString,
120+
Optional: true,
121+
Description: "Notice content ID.",
122+
},
123+
"remind_type": {
124+
Type: schema.TypeInt,
125+
Optional: true,
126+
Description: "Remind type. 0: Do not remind; 1: Specified person; 2: Everyone.",
127+
},
128+
"mobiles": {
129+
Type: schema.TypeSet,
130+
Optional: true,
131+
Elem: &schema.Schema{Type: schema.TypeString},
132+
Description: "Telephone list.",
133+
},
134+
"user_ids": {
135+
Type: schema.TypeSet,
136+
Optional: true,
137+
Elem: &schema.Schema{Type: schema.TypeString},
138+
Description: "User ID list.",
139+
},
107140
"headers": {
108141
Type: schema.TypeSet,
109142
Elem: &schema.Schema{
110143
Type: schema.TypeString,
111144
},
112145
Optional: true,
113-
Description: "abandoned.",
146+
Deprecated: "This parameter is deprecated. Please use `notice_content_id`.",
147+
Description: "Request headers.",
114148
},
115149
"body": {
116150
Type: schema.TypeString,
117151
Optional: true,
118-
Description: "abandoned.",
152+
Deprecated: "This parameter is deprecated. Please use `notice_content_id`.",
153+
Description: "Request body.",
119154
},
120155
"index": {
121156
Type: schema.TypeInt,
122157
Optional: true,
123-
Description: "index.",
158+
Computed: true,
159+
Description: "Index. The input parameter is invalid, but the output parameter is valid.",
124160
},
125161
},
126162
},
@@ -175,14 +211,17 @@ func resourceTencentCloudClsAlarmNoticeCreate(d *schema.ResourceData, meta inter
175211
noticeReceiver.ReceiverChannels = append(noticeReceiver.ReceiverChannels, &receiverChannels)
176212
}
177213
}
178-
if v, ok := dMap["start_time"]; ok {
179-
noticeReceiver.StartTime = helper.String(v.(string))
214+
if v, ok := dMap["notice_content_id"].(string); ok && v != "" {
215+
noticeReceiver.NoticeContentId = helper.String(v)
216+
}
217+
if v, ok := dMap["start_time"].(string); ok && v != "" {
218+
noticeReceiver.StartTime = helper.String(v)
180219
}
181-
if v, ok := dMap["end_time"]; ok {
182-
noticeReceiver.EndTime = helper.String(v.(string))
220+
if v, ok := dMap["end_time"].(string); ok && v != "" {
221+
noticeReceiver.EndTime = helper.String(v)
183222
}
184-
if v, ok := dMap["index"]; ok {
185-
noticeReceiver.Index = helper.IntInt64(v.(int))
223+
if v, ok := dMap["index"].(int); ok && v != 0 {
224+
noticeReceiver.Index = helper.IntInt64(v)
186225
}
187226
request.NoticeReceivers = append(request.NoticeReceivers, &noticeReceiver)
188227
}
@@ -192,14 +231,37 @@ func resourceTencentCloudClsAlarmNoticeCreate(d *schema.ResourceData, meta inter
192231
for _, item := range v.([]interface{}) {
193232
dMap := item.(map[string]interface{})
194233
webCallback := cls.WebCallback{}
234+
if v, ok := dMap["callback_type"]; ok {
235+
webCallback.CallbackType = helper.String(v.(string))
236+
}
195237
if v, ok := dMap["url"]; ok {
196238
webCallback.Url = helper.String(v.(string))
197239
}
198-
if v, ok := dMap["callback_type"]; ok {
199-
webCallback.CallbackType = helper.String(v.(string))
240+
if v, ok := dMap["web_callback_id"].(string); ok && v != "" {
241+
webCallback.WebCallbackId = helper.String(v)
242+
}
243+
if v, ok := dMap["method"].(string); ok && v != "" {
244+
webCallback.Method = helper.String(v)
200245
}
201-
if v, ok := dMap["method"]; ok {
202-
webCallback.Method = helper.String(v.(string))
246+
if v, ok := dMap["notice_content_id"].(string); ok && v != "" {
247+
webCallback.NoticeContentId = helper.String(v)
248+
}
249+
if v, ok := dMap["remind_type"]; ok {
250+
webCallback.RemindType = helper.IntUint64(v.(int))
251+
}
252+
if v, ok := dMap["mobiles"]; ok {
253+
mobilesSet := v.(*schema.Set).List()
254+
for i := range mobilesSet {
255+
mobile := mobilesSet[i].(string)
256+
webCallback.Mobiles = append(webCallback.Mobiles, &mobile)
257+
}
258+
}
259+
if v, ok := dMap["user_ids"]; ok {
260+
userIdsSet := v.(*schema.Set).List()
261+
for i := range userIdsSet {
262+
userId := userIdsSet[i].(string)
263+
webCallback.UserIds = append(webCallback.UserIds, &userId)
264+
}
203265
}
204266
if v, ok := dMap["headers"]; ok {
205267
headersSet := v.(*schema.Set).List()
@@ -211,8 +273,8 @@ func resourceTencentCloudClsAlarmNoticeCreate(d *schema.ResourceData, meta inter
211273
if v, ok := dMap["body"]; ok {
212274
webCallback.Body = helper.String(v.(string))
213275
}
214-
if v, ok := dMap["index"]; ok {
215-
webCallback.Index = helper.IntInt64(v.(int))
276+
if v, ok := dMap["index"].(int); ok && v != 0 {
277+
webCallback.Index = helper.IntInt64(v)
216278
}
217279
request.WebCallbacks = append(request.WebCallbacks, &webCallback)
218280
}
@@ -297,6 +359,10 @@ func resourceTencentCloudClsAlarmNoticeRead(d *schema.ResourceData, meta interfa
297359
noticeReceiversMap["receiver_channels"] = noticeReceiver.ReceiverChannels
298360
}
299361

362+
if noticeReceiver.NoticeContentId != nil {
363+
noticeReceiversMap["notice_content_id"] = noticeReceiver.NoticeContentId
364+
}
365+
300366
if noticeReceiver.StartTime != nil {
301367
noticeReceiversMap["start_time"] = noticeReceiver.StartTime
302368
}
@@ -321,20 +387,55 @@ func resourceTencentCloudClsAlarmNoticeRead(d *schema.ResourceData, meta interfa
321387
for _, webCallback := range alarmNotice.WebCallbacks {
322388
webCallbacksMap := map[string]interface{}{}
323389

390+
if webCallback.CallbackType != nil {
391+
webCallbacksMap["callback_type"] = webCallback.CallbackType
392+
}
393+
324394
if webCallback.Url != nil {
325395
webCallbacksMap["url"] = webCallback.Url
326396
}
327397

328-
if webCallback.CallbackType != nil {
329-
webCallbacksMap["callback_type"] = webCallback.CallbackType
398+
if webCallback.WebCallbackId != nil {
399+
webCallbacksMap["web_callback_id"] = webCallback.WebCallbackId
330400
}
331401

332402
if webCallback.Method != nil {
333403
webCallbacksMap["method"] = webCallback.Method
334404
}
335405

406+
if webCallback.NoticeContentId != nil {
407+
webCallbacksMap["notice_content_id"] = webCallback.NoticeContentId
408+
}
409+
410+
if webCallback.RemindType != nil {
411+
webCallbacksMap["remind_type"] = webCallback.RemindType
412+
}
413+
414+
if webCallback.Mobiles != nil {
415+
tmpList := make([]string, 0, len(webCallback.Mobiles))
416+
for _, item := range webCallback.Mobiles {
417+
tmpList = append(tmpList, *item)
418+
}
419+
420+
webCallbacksMap["mobiles"] = tmpList
421+
}
422+
423+
if webCallback.UserIds != nil {
424+
tmpList := make([]string, 0, len(webCallback.UserIds))
425+
for _, item := range webCallback.UserIds {
426+
tmpList = append(tmpList, *item)
427+
}
428+
429+
webCallbacksMap["user_ids"] = tmpList
430+
}
431+
336432
if webCallback.Headers != nil {
337-
webCallbacksMap["headers"] = webCallback.Headers
433+
tmpList := make([]string, 0, len(webCallback.Headers))
434+
for _, item := range webCallback.Headers {
435+
tmpList = append(tmpList, *item)
436+
}
437+
438+
webCallbacksMap["headers"] = tmpList
338439
}
339440

340441
if webCallback.Body != nil {
@@ -397,8 +498,8 @@ func resourceTencentCloudClsAlarmNoticeUpdate(d *schema.ResourceData, meta inter
397498

398499
if v, ok := d.GetOk("notice_receivers"); ok {
399500
for _, item := range v.([]interface{}) {
400-
noticeReceiver := cls.NoticeReceiver{}
401501
dMap := item.(map[string]interface{})
502+
noticeReceiver := cls.NoticeReceiver{}
402503
if v, ok := dMap["receiver_type"]; ok {
403504
noticeReceiver.ReceiverType = helper.String(v.(string))
404505
}
@@ -416,31 +517,57 @@ func resourceTencentCloudClsAlarmNoticeUpdate(d *schema.ResourceData, meta inter
416517
noticeReceiver.ReceiverChannels = append(noticeReceiver.ReceiverChannels, &receiverChannels)
417518
}
418519
}
419-
if v, ok := dMap["start_time"]; ok {
420-
noticeReceiver.StartTime = helper.String(v.(string))
520+
if v, ok := dMap["notice_content_id"].(string); ok && v != "" {
521+
noticeReceiver.NoticeContentId = helper.String(v)
421522
}
422-
if v, ok := dMap["end_time"]; ok {
423-
noticeReceiver.EndTime = helper.String(v.(string))
523+
if v, ok := dMap["start_time"].(string); ok && v != "" {
524+
noticeReceiver.StartTime = helper.String(v)
424525
}
425-
if v, ok := dMap["index"]; ok {
426-
noticeReceiver.Index = helper.IntInt64(v.(int))
526+
if v, ok := dMap["end_time"].(string); ok && v != "" {
527+
noticeReceiver.EndTime = helper.String(v)
528+
}
529+
if v, ok := dMap["index"].(int); ok && v != 0 {
530+
noticeReceiver.Index = helper.IntInt64(v)
427531
}
428532
request.NoticeReceivers = append(request.NoticeReceivers, &noticeReceiver)
429533
}
430534
}
431535

432536
if v, ok := d.GetOk("web_callbacks"); ok {
433537
for _, item := range v.([]interface{}) {
434-
webCallback := cls.WebCallback{}
435538
dMap := item.(map[string]interface{})
539+
webCallback := cls.WebCallback{}
540+
if v, ok := dMap["callback_type"]; ok {
541+
webCallback.CallbackType = helper.String(v.(string))
542+
}
436543
if v, ok := dMap["url"]; ok {
437544
webCallback.Url = helper.String(v.(string))
438545
}
439-
if v, ok := dMap["callback_type"]; ok {
440-
webCallback.CallbackType = helper.String(v.(string))
546+
if v, ok := dMap["web_callback_id"].(string); ok && v != "" {
547+
webCallback.WebCallbackId = helper.String(v)
548+
}
549+
if v, ok := dMap["method"].(string); ok && v != "" {
550+
webCallback.Method = helper.String(v)
551+
}
552+
if v, ok := dMap["notice_content_id"].(string); ok && v != "" {
553+
webCallback.NoticeContentId = helper.String(v)
441554
}
442-
if v, ok := dMap["method"]; ok {
443-
webCallback.Method = helper.String(v.(string))
555+
if v, ok := dMap["remind_type"]; ok {
556+
webCallback.RemindType = helper.IntUint64(v.(int))
557+
}
558+
if v, ok := dMap["mobiles"]; ok {
559+
mobilesSet := v.(*schema.Set).List()
560+
for i := range mobilesSet {
561+
mobile := mobilesSet[i].(string)
562+
webCallback.Mobiles = append(webCallback.Mobiles, &mobile)
563+
}
564+
}
565+
if v, ok := dMap["user_ids"]; ok {
566+
userIdsSet := v.(*schema.Set).List()
567+
for i := range userIdsSet {
568+
userId := userIdsSet[i].(string)
569+
webCallback.UserIds = append(webCallback.UserIds, &userId)
570+
}
444571
}
445572
if v, ok := dMap["headers"]; ok {
446573
headersSet := v.(*schema.Set).List()
@@ -452,8 +579,8 @@ func resourceTencentCloudClsAlarmNoticeUpdate(d *schema.ResourceData, meta inter
452579
if v, ok := dMap["body"]; ok {
453580
webCallback.Body = helper.String(v.(string))
454581
}
455-
if v, ok := dMap["index"]; ok {
456-
webCallback.Index = helper.IntInt64(v.(int))
582+
if v, ok := dMap["index"].(int); ok && v != 0 {
583+
webCallback.Index = helper.IntInt64(v)
457584
}
458585
request.WebCallbacks = append(request.WebCallbacks, &webCallback)
459586
}

0 commit comments

Comments
 (0)