Skip to content

Commit 97bceaa

Browse files
authored
Feat/notices (#1187)
* feat: add datasource alarm-notices * feat: add datasource alarm-notices * feat: add resource alarm-notices * feat: update resource/datasource alarm-notice * feat: update resource/datasource alarm-notice * feat: update resource/datasource alarm-notice * feat: add service alarm-notices * feat: update resource/datasource alarm-notice * feat: update resource/datasource alarm-notice-test * feat: update resource/datasource alarm-notice * feat: update resource/datasource alarm-notice * feat: update resource/datasource alarm-notice * feat: update docs alarm-notice * feat: update test alarm-notice * feat: update test alarm-notice * feat: update doc alarm-notice * Delete outputs.tf * Delete provider.tf * Delete vpc.tf
1 parent a2422fd commit 97bceaa

9 files changed

+1411
-0
lines changed
Lines changed: 397 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,397 @@
1+
/*
2+
Use this data source to Interlude notification list.
3+
4+
Example Usage
5+
6+
```hcl
7+
data "tencentcloud_monitor_alarm_notices" "notices" {
8+
order = "DESC"
9+
owner_uid = 1
10+
name = ""
11+
receiver_type = ""
12+
user_ids = []
13+
group_ids = []
14+
notice_ids = []
15+
}
16+
```
17+
18+
*/
19+
package tencentcloud
20+
21+
import (
22+
"context"
23+
"crypto/md5"
24+
"fmt"
25+
26+
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
27+
monitor "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/monitor/v20180724"
28+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
29+
)
30+
31+
func dataSourceTencentMonitorAlarmNotices() *schema.Resource {
32+
return &schema.Resource{
33+
Read: dataSourceTencentMonitorAlarmNoticesRead,
34+
Schema: map[string]*schema.Schema{
35+
"order": {
36+
Type: schema.TypeString,
37+
Optional: true,
38+
Default: "ASC",
39+
Description: "Sort by update time ASC=forward order DESC=reverse order.",
40+
},
41+
"owner_uid": {
42+
Type: schema.TypeInt,
43+
Optional: true,
44+
Description: "The primary account uid is used to create a preset notification.",
45+
},
46+
"name": {
47+
Type: schema.TypeString,
48+
Optional: true,
49+
Description: "Alarm notification template name Used for fuzzy search.",
50+
},
51+
"receiver_type": {
52+
Type: schema.TypeString,
53+
Optional: true,
54+
Description: "To filter alarm notification templates according to recipients, you need to select the notification user type. USER=user GROUP=user group Leave blank = not filter by recipient.",
55+
},
56+
"user_ids": {
57+
Type: schema.TypeSet,
58+
Optional: true,
59+
Description: "List of recipients.",
60+
Elem: &schema.Schema{Type: schema.TypeInt},
61+
},
62+
"group_ids": {
63+
Type: schema.TypeSet,
64+
Optional: true,
65+
Description: "Receive group list.",
66+
Elem: &schema.Schema{Type: schema.TypeInt},
67+
},
68+
"notice_ids": {
69+
Type: schema.TypeSet,
70+
Optional: true,
71+
Description: "Receive group list.",
72+
Elem: &schema.Schema{Type: schema.TypeString},
73+
},
74+
75+
"result_output_file": {
76+
Type: schema.TypeString,
77+
Optional: true,
78+
Description: "Used to store results.",
79+
},
80+
81+
"alarm_notice": {
82+
Type: schema.TypeList,
83+
Computed: true,
84+
Description: "Alarm notification template list.",
85+
Elem: &schema.Resource{
86+
Schema: map[string]*schema.Schema{
87+
"id": {
88+
Type: schema.TypeString,
89+
Computed: true,
90+
Description: "Alarm notification template ID.",
91+
},
92+
"name": {
93+
Type: schema.TypeString,
94+
Computed: true,
95+
Description: "Alarm notification template name.",
96+
},
97+
"updated_at": {
98+
Type: schema.TypeString,
99+
Computed: true,
100+
Description: "Last modified time.",
101+
},
102+
"updated_by": {
103+
Type: schema.TypeString,
104+
Computed: true,
105+
Description: "Last Modified By.",
106+
},
107+
"notice_type": {
108+
Type: schema.TypeString,
109+
Computed: true,
110+
Description: "Alarm notification type ALARM=Notification not restored OK=Notification restored ALL.",
111+
},
112+
"user_notices": {
113+
Type: schema.TypeList,
114+
Computed: true,
115+
Description: "Alarm notification template list.(At most five).",
116+
Elem: &schema.Resource{
117+
Schema: map[string]*schema.Schema{
118+
"receiver_type": {
119+
Type: schema.TypeString,
120+
Computed: true,
121+
Description: "Recipient Type USER=User GROUP=User Group.",
122+
},
123+
"start_time": {
124+
Type: schema.TypeInt,
125+
Computed: true,
126+
Description: "The number of seconds since the notification start time 00:00:00 (value range 0-86399).",
127+
},
128+
"end_time": {
129+
Type: schema.TypeInt,
130+
Computed: true,
131+
Description: "The number of seconds since the notification end time 00:00:00 (value range 0-86399).",
132+
},
133+
"notice_way": {
134+
Type: schema.TypeSet,
135+
Computed: true,
136+
Description: "Notification Channel List EMAIL=Mail SMS=SMS CALL=Telephone WECHAT=WeChat RTX=Enterprise WeChat.",
137+
Elem: &schema.Schema{Type: schema.TypeString},
138+
},
139+
"user_ids": {
140+
Type: schema.TypeSet,
141+
Computed: true,
142+
Description: "User UID List.",
143+
Elem: &schema.Schema{Type: schema.TypeInt},
144+
},
145+
"group_ids": {
146+
Type: schema.TypeSet,
147+
Computed: true,
148+
Description: "User group ID list.",
149+
Elem: &schema.Schema{Type: schema.TypeInt},
150+
},
151+
"phone_order": {
152+
Type: schema.TypeSet,
153+
Computed: true,
154+
Description: "Telephone polling list.",
155+
Elem: &schema.Schema{Type: schema.TypeInt},
156+
},
157+
"phone_circle_times": {
158+
Type: schema.TypeInt,
159+
Computed: true,
160+
Description: "Number of telephone polls (value range: 1-5).",
161+
},
162+
"phone_inner_interval": {
163+
Type: schema.TypeInt,
164+
Computed: true,
165+
Description: "Number of seconds between calls in a polling session (value range: 60-900).",
166+
},
167+
"phone_circle_interval": {
168+
Type: schema.TypeInt,
169+
Computed: true,
170+
Description: "Number of seconds between polls (value range: 60-900).",
171+
},
172+
"need_phone_arrive_notice": {
173+
Type: schema.TypeInt,
174+
Computed: true,
175+
Description: "Contact notification required 0= No 1= Yes.",
176+
},
177+
"phone_call_type": {
178+
Type: schema.TypeString,
179+
Computed: true,
180+
Description: "Call type SYNC= Simultaneous call CIRCLE= Round call If this parameter is not specified, the default value is round call.",
181+
},
182+
"weekday": {
183+
Type: schema.TypeSet,
184+
Computed: true,
185+
Description: "Notification period 1-7 indicates Monday to Sunday.",
186+
Elem: &schema.Schema{Type: schema.TypeInt},
187+
},
188+
},
189+
},
190+
},
191+
"url_notices": {
192+
Type: schema.TypeList,
193+
Computed: true,
194+
Description: "The maximum number of callback notifications is 3.",
195+
Elem: &schema.Resource{
196+
Schema: map[string]*schema.Schema{
197+
"url": {
198+
Type: schema.TypeString,
199+
Computed: true,
200+
Description: "Callback URL (limited to 256 characters).",
201+
},
202+
"start_time": {
203+
Type: schema.TypeInt,
204+
Computed: true,
205+
Description: "Notification Start Time Number of seconds at the start of a day.",
206+
},
207+
"end_time": {
208+
Type: schema.TypeInt,
209+
Computed: true,
210+
Description: "Notification End Time Seconds at the start of a day.",
211+
},
212+
"weekday": {
213+
Type: schema.TypeSet,
214+
Computed: true,
215+
Description: "Notification period 1-7 indicates Monday to Sunday.",
216+
Elem: &schema.Schema{Type: schema.TypeInt},
217+
},
218+
},
219+
},
220+
},
221+
"cls_notices": {
222+
Type: schema.TypeList,
223+
Computed: true,
224+
Description: "A maximum of one alarm notification can be pushed to the CLS service.",
225+
Elem: &schema.Resource{
226+
Schema: map[string]*schema.Schema{
227+
"region": {
228+
Type: schema.TypeString,
229+
Computed: true,
230+
Description: "Regional.",
231+
},
232+
"log_set_id": {
233+
Type: schema.TypeString,
234+
Computed: true,
235+
Description: "Log collection Id.",
236+
},
237+
"topic_id": {
238+
Type: schema.TypeString,
239+
Computed: true,
240+
Description: "Theme Id.",
241+
},
242+
"enable": {
243+
Type: schema.TypeInt,
244+
Computed: true,
245+
Description: "Start-stop status, can not be transmitted, default enabled. 0= Disabled, 1= enabled.",
246+
},
247+
},
248+
},
249+
},
250+
"is_preset": {
251+
Type: schema.TypeInt,
252+
Computed: true,
253+
Description: "Whether it is the system default notification template 0=No 1=Yes.",
254+
},
255+
"notice_language": {
256+
Type: schema.TypeString,
257+
Computed: true,
258+
Description: "Notification language zh-CN=Chinese en-US=English.",
259+
},
260+
"policy_ids": {
261+
Type: schema.TypeSet,
262+
Computed: true,
263+
Description: "List of alarm policy IDs bound to the alarm notification template.",
264+
Elem: &schema.Schema{Type: schema.TypeString},
265+
},
266+
},
267+
},
268+
},
269+
},
270+
}
271+
}
272+
273+
func dataSourceTencentMonitorAlarmNoticesRead(d *schema.ResourceData, meta interface{}) error {
274+
defer logElapsed("data_source.tencentcloud_monitor_alarm_notices.read")()
275+
276+
var (
277+
monitorService = MonitorService{client: meta.(*TencentCloudClient).apiV3Conn}
278+
err error
279+
alarmNotices []interface{}
280+
alarmNotice []*monitor.AlarmNotice
281+
)
282+
283+
logId := getLogId(contextNil)
284+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
285+
286+
alarmNoticeMap := make(map[string]interface{})
287+
alarmNoticeMap["order"] = helper.String(d.Get("order").(string))
288+
289+
if v, ok := d.GetOk("owner_uid"); ok {
290+
alarmNoticeMap["ownerUid"] = helper.IntInt64(v.(int))
291+
}
292+
if v, ok := d.GetOk("name"); ok {
293+
alarmNoticeMap["name"] = helper.String(v.(string))
294+
}
295+
if v, ok := d.GetOk("receiver_type"); ok {
296+
alarmNoticeMap["receiverType"] = helper.String(v.(string))
297+
}
298+
299+
if v, ok := d.GetOk("user_ids"); ok {
300+
userIds := v.(*schema.Set).List()
301+
userIdsArr := make([]*int64, 0, len(userIds))
302+
for _, userId := range userIds {
303+
userIdsArr = append(userIdsArr, helper.Int64(userId.(int64)))
304+
}
305+
alarmNoticeMap["userIdArr"] = userIdsArr
306+
}
307+
308+
if v, ok := d.GetOk("group_ids"); ok {
309+
groupIds := v.(*schema.Set).List()
310+
groupIdsArr := make([]*int64, 0, len(groupIds))
311+
for _, groupId := range groupIds {
312+
groupIdsArr = append(groupIdsArr, helper.Int64(groupId.(int64)))
313+
}
314+
alarmNoticeMap["groupArr"] = groupIdsArr
315+
}
316+
317+
if v, ok := d.GetOk("notice_ids"); ok {
318+
noticeIds := v.(*schema.Set).List()
319+
noticeIdsArr := make([]*string, 0, len(noticeIds))
320+
for _, noticeId := range noticeIds {
321+
noticeIdsArr = append(noticeIdsArr, helper.String(noticeId.(string)))
322+
}
323+
alarmNoticeMap["noticeArr"] = noticeIdsArr
324+
}
325+
326+
alarmNotice, err = monitorService.DescribeAlarmNoticeById(ctx, alarmNoticeMap)
327+
if err != nil {
328+
return err
329+
}
330+
for _, noticesItem := range alarmNotice {
331+
noticesItemMap := map[string]interface{}{
332+
"id": noticesItem.Id,
333+
"name": noticesItem.Name,
334+
"updated_at": noticesItem.UpdatedAt,
335+
"updated_by": noticesItem.UpdatedBy,
336+
"notice_type": noticesItem.NoticeType,
337+
"is_preset": noticesItem.IsPreset,
338+
"notice_language": noticesItem.NoticeLanguage,
339+
"policy_ids": noticesItem.PolicyIds,
340+
}
341+
342+
userNoticesItems := make([]interface{}, 0, 100)
343+
for _, userNotices := range noticesItem.UserNotices {
344+
userNoticesItems = append(userNoticesItems, map[string]interface{}{
345+
"receiver_type": userNotices.ReceiverType,
346+
"start_time": userNotices.StartTime,
347+
"end_time": userNotices.EndTime,
348+
"notice_way": userNotices.NoticeWay,
349+
"user_ids": userNotices.UserIds,
350+
"group_ids": userNotices.GroupIds,
351+
"phone_order": userNotices.PhoneOrder,
352+
"phone_circle_times": userNotices.PhoneCircleTimes,
353+
"phone_inner_interval": userNotices.PhoneInnerInterval,
354+
"phone_circle_interval": userNotices.PhoneCircleInterval,
355+
"need_phone_arrive_notice": userNotices.NeedPhoneArriveNotice,
356+
"phone_call_type": userNotices.PhoneCallType,
357+
"weekday": userNotices.Weekday,
358+
})
359+
}
360+
361+
urlNoticesItems := make([]interface{}, 0, 100)
362+
for _, urlNotice := range noticesItem.URLNotices {
363+
urlNoticesItems = append(urlNoticesItems, map[string]interface{}{
364+
"url": urlNotice.URL,
365+
"start_time": urlNotice.StartTime,
366+
"end_time": urlNotice.EndTime,
367+
"weekday": urlNotice.Weekday,
368+
})
369+
}
370+
371+
clsNoticesItems := make([]interface{}, 0, 100)
372+
for _, clsNotice := range noticesItem.CLSNotices {
373+
clsNoticesItems = append(clsNoticesItems, map[string]interface{}{
374+
"region": clsNotice.Region,
375+
"log_set_id": clsNotice.LogSetId,
376+
"topic_id": clsNotice.TopicId,
377+
"enable": clsNotice.Enable,
378+
})
379+
}
380+
noticesItemMap["user_notices"] = userNoticesItems
381+
noticesItemMap["url_notices"] = urlNoticesItems
382+
noticesItemMap["cls_notices"] = clsNoticesItems
383+
alarmNotices = append(alarmNotices, noticesItemMap)
384+
}
385+
386+
md := md5.New()
387+
id := fmt.Sprintf("%x", md.Sum(nil))
388+
d.SetId(id)
389+
390+
if err = d.Set("alarm_notice", alarmNotices); err != nil {
391+
return err
392+
}
393+
if output, ok := d.GetOk("result_output_file"); ok {
394+
return writeToFile(output.(string), alarmNotices)
395+
}
396+
return nil
397+
}

0 commit comments

Comments
 (0)