From 4476534e08080eb5480e61cafe6f9807c96c098d Mon Sep 17 00:00:00 2001 From: SevenEarth <45937856+SevenEarth@users.noreply.github.com> Date: Mon, 9 Dec 2024 10:07:49 +0800 Subject: [PATCH] fix(cls): [121076867] `tencentcloud_cls_alarm_notice` add new params (#3000) * add * add --- .changelog/3000.txt | 3 + .../cls/resource_tc_cls_alarm_notice.go | 219 ++++++++++++++---- .../cls/resource_tc_cls_alarm_notice.md | 41 ++-- .../cls/resource_tc_cls_notice_content.go | 2 +- website/docs/r/cls_alarm_notice.html.markdown | 79 ++++--- .../docs/r/cls_notice_content.html.markdown | 2 +- 6 files changed, 250 insertions(+), 96 deletions(-) create mode 100644 .changelog/3000.txt diff --git a/.changelog/3000.txt b/.changelog/3000.txt new file mode 100644 index 0000000000..ae1f7ab593 --- /dev/null +++ b/.changelog/3000.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_cls_alarm_notice: add new params +``` \ No newline at end of file diff --git a/tencentcloud/services/cls/resource_tc_cls_alarm_notice.go b/tencentcloud/services/cls/resource_tc_cls_alarm_notice.go index 7abb391ec1..6886f37b29 100644 --- a/tencentcloud/services/cls/resource_tc_cls_alarm_notice.go +++ b/tencentcloud/services/cls/resource_tc_cls_alarm_notice.go @@ -28,25 +28,25 @@ func ResourceTencentCloudClsAlarmNotice() *schema.Resource { "name": { Required: true, Type: schema.TypeString, - Description: "alarm notice name.", + Description: "Alarm notice name.", }, "type": { Required: true, Type: schema.TypeString, - Description: "notice type.", + Description: "Notice type. Value: Trigger, Recovery, All.", }, "notice_receivers": { Optional: true, Type: schema.TypeList, - Description: "notice receivers.", + Description: "Notice receivers.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "receiver_type": { Type: schema.TypeString, Required: true, - Description: "receiver type, Uin or Group.", + Description: "Receiver type, Uin or Group.", }, "receiver_ids": { Type: schema.TypeSet, @@ -54,7 +54,7 @@ func ResourceTencentCloudClsAlarmNotice() *schema.Resource { Type: schema.TypeInt, }, Required: true, - Description: "receiver id.", + Description: "Receiver id list.", }, "receiver_channels": { Type: schema.TypeSet, @@ -62,22 +62,28 @@ func ResourceTencentCloudClsAlarmNotice() *schema.Resource { Type: schema.TypeString, }, Required: true, - Description: "receiver channels, Email,Sms,WeChat or Phone.", + Description: "Receiver channels, Value: Email, Sms, WeChat, Phone.", + }, + "notice_content_id": { + Type: schema.TypeString, + Optional: true, + Description: "Notice content ID.", }, "start_time": { Type: schema.TypeString, Optional: true, - Description: "start time allowed to receive messages.", + Description: "Start time allowed to receive messages.", }, "end_time": { Type: schema.TypeString, Optional: true, - Description: "end time allowed to receive messages.", + Description: "End time allowed to receive messages.", }, "index": { Type: schema.TypeInt, Optional: true, - Description: "index.", + Computed: true, + Description: "Index. The input parameter is invalid, but the output parameter is valid.", }, }, }, @@ -86,41 +92,71 @@ func ResourceTencentCloudClsAlarmNotice() *schema.Resource { "web_callbacks": { Optional: true, Type: schema.TypeList, - Description: "callback info.", + Description: "Callback info.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "url": { + "callback_type": { Type: schema.TypeString, Required: true, - Description: "callback url.", + Description: "Callback type, Values: Http, WeCom, DingTalk, Lark.", }, - "callback_type": { + "url": { Type: schema.TypeString, Required: true, - Description: "callback type, WeCom or Http.", + Description: "Callback url.", + }, + "web_callback_id": { + Type: schema.TypeString, + Optional: true, + Description: "Integration configuration ID.", }, "method": { Type: schema.TypeString, Optional: true, Description: "Method, POST or PUT.", }, + "notice_content_id": { + Type: schema.TypeString, + Optional: true, + Description: "Notice content ID.", + }, + "remind_type": { + Type: schema.TypeInt, + Optional: true, + Description: "Remind type. 0: Do not remind; 1: Specified person; 2: Everyone.", + }, + "mobiles": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Description: "Telephone list.", + }, + "user_ids": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Description: "User ID list.", + }, "headers": { Type: schema.TypeSet, Elem: &schema.Schema{ Type: schema.TypeString, }, Optional: true, - Description: "abandoned.", + Deprecated: "This parameter is deprecated. Please use `notice_content_id`.", + Description: "Request headers.", }, "body": { Type: schema.TypeString, Optional: true, - Description: "abandoned.", + Deprecated: "This parameter is deprecated. Please use `notice_content_id`.", + Description: "Request body.", }, "index": { Type: schema.TypeInt, Optional: true, - Description: "index.", + Computed: true, + Description: "Index. The input parameter is invalid, but the output parameter is valid.", }, }, }, @@ -175,14 +211,17 @@ func resourceTencentCloudClsAlarmNoticeCreate(d *schema.ResourceData, meta inter noticeReceiver.ReceiverChannels = append(noticeReceiver.ReceiverChannels, &receiverChannels) } } - if v, ok := dMap["start_time"]; ok { - noticeReceiver.StartTime = helper.String(v.(string)) + if v, ok := dMap["notice_content_id"].(string); ok && v != "" { + noticeReceiver.NoticeContentId = helper.String(v) + } + if v, ok := dMap["start_time"].(string); ok && v != "" { + noticeReceiver.StartTime = helper.String(v) } - if v, ok := dMap["end_time"]; ok { - noticeReceiver.EndTime = helper.String(v.(string)) + if v, ok := dMap["end_time"].(string); ok && v != "" { + noticeReceiver.EndTime = helper.String(v) } - if v, ok := dMap["index"]; ok { - noticeReceiver.Index = helper.IntInt64(v.(int)) + if v, ok := dMap["index"].(int); ok && v != 0 { + noticeReceiver.Index = helper.IntInt64(v) } request.NoticeReceivers = append(request.NoticeReceivers, ¬iceReceiver) } @@ -192,14 +231,37 @@ func resourceTencentCloudClsAlarmNoticeCreate(d *schema.ResourceData, meta inter for _, item := range v.([]interface{}) { dMap := item.(map[string]interface{}) webCallback := cls.WebCallback{} + if v, ok := dMap["callback_type"]; ok { + webCallback.CallbackType = helper.String(v.(string)) + } if v, ok := dMap["url"]; ok { webCallback.Url = helper.String(v.(string)) } - if v, ok := dMap["callback_type"]; ok { - webCallback.CallbackType = helper.String(v.(string)) + if v, ok := dMap["web_callback_id"].(string); ok && v != "" { + webCallback.WebCallbackId = helper.String(v) + } + if v, ok := dMap["method"].(string); ok && v != "" { + webCallback.Method = helper.String(v) } - if v, ok := dMap["method"]; ok { - webCallback.Method = helper.String(v.(string)) + if v, ok := dMap["notice_content_id"].(string); ok && v != "" { + webCallback.NoticeContentId = helper.String(v) + } + if v, ok := dMap["remind_type"]; ok { + webCallback.RemindType = helper.IntUint64(v.(int)) + } + if v, ok := dMap["mobiles"]; ok { + mobilesSet := v.(*schema.Set).List() + for i := range mobilesSet { + mobile := mobilesSet[i].(string) + webCallback.Mobiles = append(webCallback.Mobiles, &mobile) + } + } + if v, ok := dMap["user_ids"]; ok { + userIdsSet := v.(*schema.Set).List() + for i := range userIdsSet { + userId := userIdsSet[i].(string) + webCallback.UserIds = append(webCallback.UserIds, &userId) + } } if v, ok := dMap["headers"]; ok { headersSet := v.(*schema.Set).List() @@ -211,8 +273,8 @@ func resourceTencentCloudClsAlarmNoticeCreate(d *schema.ResourceData, meta inter if v, ok := dMap["body"]; ok { webCallback.Body = helper.String(v.(string)) } - if v, ok := dMap["index"]; ok { - webCallback.Index = helper.IntInt64(v.(int)) + if v, ok := dMap["index"].(int); ok && v != 0 { + webCallback.Index = helper.IntInt64(v) } request.WebCallbacks = append(request.WebCallbacks, &webCallback) } @@ -297,6 +359,10 @@ func resourceTencentCloudClsAlarmNoticeRead(d *schema.ResourceData, meta interfa noticeReceiversMap["receiver_channels"] = noticeReceiver.ReceiverChannels } + if noticeReceiver.NoticeContentId != nil { + noticeReceiversMap["notice_content_id"] = noticeReceiver.NoticeContentId + } + if noticeReceiver.StartTime != nil { noticeReceiversMap["start_time"] = noticeReceiver.StartTime } @@ -321,20 +387,55 @@ func resourceTencentCloudClsAlarmNoticeRead(d *schema.ResourceData, meta interfa for _, webCallback := range alarmNotice.WebCallbacks { webCallbacksMap := map[string]interface{}{} + if webCallback.CallbackType != nil { + webCallbacksMap["callback_type"] = webCallback.CallbackType + } + if webCallback.Url != nil { webCallbacksMap["url"] = webCallback.Url } - if webCallback.CallbackType != nil { - webCallbacksMap["callback_type"] = webCallback.CallbackType + if webCallback.WebCallbackId != nil { + webCallbacksMap["web_callback_id"] = webCallback.WebCallbackId } if webCallback.Method != nil { webCallbacksMap["method"] = webCallback.Method } + if webCallback.NoticeContentId != nil { + webCallbacksMap["notice_content_id"] = webCallback.NoticeContentId + } + + if webCallback.RemindType != nil { + webCallbacksMap["remind_type"] = webCallback.RemindType + } + + if webCallback.Mobiles != nil { + tmpList := make([]string, 0, len(webCallback.Mobiles)) + for _, item := range webCallback.Mobiles { + tmpList = append(tmpList, *item) + } + + webCallbacksMap["mobiles"] = tmpList + } + + if webCallback.UserIds != nil { + tmpList := make([]string, 0, len(webCallback.UserIds)) + for _, item := range webCallback.UserIds { + tmpList = append(tmpList, *item) + } + + webCallbacksMap["user_ids"] = tmpList + } + if webCallback.Headers != nil { - webCallbacksMap["headers"] = webCallback.Headers + tmpList := make([]string, 0, len(webCallback.Headers)) + for _, item := range webCallback.Headers { + tmpList = append(tmpList, *item) + } + + webCallbacksMap["headers"] = tmpList } if webCallback.Body != nil { @@ -397,8 +498,8 @@ func resourceTencentCloudClsAlarmNoticeUpdate(d *schema.ResourceData, meta inter if v, ok := d.GetOk("notice_receivers"); ok { for _, item := range v.([]interface{}) { - noticeReceiver := cls.NoticeReceiver{} dMap := item.(map[string]interface{}) + noticeReceiver := cls.NoticeReceiver{} if v, ok := dMap["receiver_type"]; ok { noticeReceiver.ReceiverType = helper.String(v.(string)) } @@ -416,14 +517,17 @@ func resourceTencentCloudClsAlarmNoticeUpdate(d *schema.ResourceData, meta inter noticeReceiver.ReceiverChannels = append(noticeReceiver.ReceiverChannels, &receiverChannels) } } - if v, ok := dMap["start_time"]; ok { - noticeReceiver.StartTime = helper.String(v.(string)) + if v, ok := dMap["notice_content_id"].(string); ok && v != "" { + noticeReceiver.NoticeContentId = helper.String(v) } - if v, ok := dMap["end_time"]; ok { - noticeReceiver.EndTime = helper.String(v.(string)) + if v, ok := dMap["start_time"].(string); ok && v != "" { + noticeReceiver.StartTime = helper.String(v) } - if v, ok := dMap["index"]; ok { - noticeReceiver.Index = helper.IntInt64(v.(int)) + if v, ok := dMap["end_time"].(string); ok && v != "" { + noticeReceiver.EndTime = helper.String(v) + } + if v, ok := dMap["index"].(int); ok && v != 0 { + noticeReceiver.Index = helper.IntInt64(v) } request.NoticeReceivers = append(request.NoticeReceivers, ¬iceReceiver) } @@ -431,16 +535,39 @@ func resourceTencentCloudClsAlarmNoticeUpdate(d *schema.ResourceData, meta inter if v, ok := d.GetOk("web_callbacks"); ok { for _, item := range v.([]interface{}) { - webCallback := cls.WebCallback{} dMap := item.(map[string]interface{}) + webCallback := cls.WebCallback{} + if v, ok := dMap["callback_type"]; ok { + webCallback.CallbackType = helper.String(v.(string)) + } if v, ok := dMap["url"]; ok { webCallback.Url = helper.String(v.(string)) } - if v, ok := dMap["callback_type"]; ok { - webCallback.CallbackType = helper.String(v.(string)) + if v, ok := dMap["web_callback_id"].(string); ok && v != "" { + webCallback.WebCallbackId = helper.String(v) + } + if v, ok := dMap["method"].(string); ok && v != "" { + webCallback.Method = helper.String(v) + } + if v, ok := dMap["notice_content_id"].(string); ok && v != "" { + webCallback.NoticeContentId = helper.String(v) } - if v, ok := dMap["method"]; ok { - webCallback.Method = helper.String(v.(string)) + if v, ok := dMap["remind_type"]; ok { + webCallback.RemindType = helper.IntUint64(v.(int)) + } + if v, ok := dMap["mobiles"]; ok { + mobilesSet := v.(*schema.Set).List() + for i := range mobilesSet { + mobile := mobilesSet[i].(string) + webCallback.Mobiles = append(webCallback.Mobiles, &mobile) + } + } + if v, ok := dMap["user_ids"]; ok { + userIdsSet := v.(*schema.Set).List() + for i := range userIdsSet { + userId := userIdsSet[i].(string) + webCallback.UserIds = append(webCallback.UserIds, &userId) + } } if v, ok := dMap["headers"]; ok { headersSet := v.(*schema.Set).List() @@ -452,8 +579,8 @@ func resourceTencentCloudClsAlarmNoticeUpdate(d *schema.ResourceData, meta inter if v, ok := dMap["body"]; ok { webCallback.Body = helper.String(v.(string)) } - if v, ok := dMap["index"]; ok { - webCallback.Index = helper.IntInt64(v.(int)) + if v, ok := dMap["index"].(int); ok && v != 0 { + webCallback.Index = helper.IntInt64(v) } request.WebCallbacks = append(request.WebCallbacks, &webCallback) } diff --git a/tencentcloud/services/cls/resource_tc_cls_alarm_notice.md b/tencentcloud/services/cls/resource_tc_cls_alarm_notice.md index 5877d82e92..b881e816e8 100644 --- a/tencentcloud/services/cls/resource_tc_cls_alarm_notice.md +++ b/tencentcloud/services/cls/resource_tc_cls_alarm_notice.md @@ -1,35 +1,44 @@ -Provides a resource to create a cls alarm_notice +Provides a resource to create a cls alarm notice Example Usage ```hcl -resource "tencentcloud_cls_alarm_notice" "alarm_notice" { - name = "terraform-alarm-notice-test" - tags = { - "createdBy" = "terraform" - } +resource "tencentcloud_cls_alarm_notice" "example" { + name = "tf-example" type = "All" notice_receivers { - index = 0 + receiver_type = "Uin" + receiver_ids = [ + 100037718139, + ] receiver_channels = [ + "Email", "Sms", ] - receiver_ids = [ - 13478043, - 15972111, - ] - receiver_type = "Uin" - start_time = "00:00:00" - end_time = "23:59:59" + notice_content_id = "noticetemplate-b417f32a-bdf9-46c5-933e-28c23cd7a6b7" + start_time = "00:00:00" + end_time = "23:59:59" + } + + web_callbacks { + callback_type = "Http" + url = "example.com" + method = "POST" + notice_content_id = "noticetemplate-b417f32a-bdf9-46c5-933e-28c23cd7a6b7" + remind_type = 1 + } + + tags = { + createdBy = "terraform" } } ``` Import -cls alarm_notice can be imported using the id, e.g. +cls alarm notice can be imported using the id, e.g. ``` -terraform import tencentcloud_cls_alarm_notice.alarm_notice alarm_notice_id +terraform import tencentcloud_cls_alarm_notice.example notice-19076f96-0f9a-4206-b308-b478737cab66 ``` \ No newline at end of file diff --git a/tencentcloud/services/cls/resource_tc_cls_notice_content.go b/tencentcloud/services/cls/resource_tc_cls_notice_content.go index a26d8d9cff..109586d7ad 100644 --- a/tencentcloud/services/cls/resource_tc_cls_notice_content.go +++ b/tencentcloud/services/cls/resource_tc_cls_notice_content.go @@ -45,7 +45,7 @@ func ResourceTencentCloudClsNoticeContent() *schema.Resource { "type": { Type: schema.TypeString, Required: true, - Description: "Channel type. Email: Email; Sms: SMS; WeChat: WeChat; Phone: Telephone; WeCom: Enterprise WeChat; DingTalk: DingTalk; Lark: Feishu; HTTP: Custom callback.", + Description: "Channel type. Email: Email; Sms: SMS; WeChat: WeChat; Phone: Telephone; WeCom: Enterprise WeChat; DingTalk: DingTalk; Lark: Feishu; Http: Custom callback.", }, "trigger_content": { Type: schema.TypeList, diff --git a/website/docs/r/cls_alarm_notice.html.markdown b/website/docs/r/cls_alarm_notice.html.markdown index a68def7d80..6a82e61541 100644 --- a/website/docs/r/cls_alarm_notice.html.markdown +++ b/website/docs/r/cls_alarm_notice.html.markdown @@ -4,35 +4,44 @@ layout: "tencentcloud" page_title: "TencentCloud: tencentcloud_cls_alarm_notice" sidebar_current: "docs-tencentcloud-resource-cls_alarm_notice" description: |- - Provides a resource to create a cls alarm_notice + Provides a resource to create a cls alarm notice --- # tencentcloud_cls_alarm_notice -Provides a resource to create a cls alarm_notice +Provides a resource to create a cls alarm notice ## Example Usage ```hcl -resource "tencentcloud_cls_alarm_notice" "alarm_notice" { - name = "terraform-alarm-notice-test" - tags = { - "createdBy" = "terraform" - } +resource "tencentcloud_cls_alarm_notice" "example" { + name = "tf-example" type = "All" notice_receivers { - index = 0 + receiver_type = "Uin" + receiver_ids = [ + 100037718139, + ] receiver_channels = [ + "Email", "Sms", ] - receiver_ids = [ - 13478043, - 15972111, - ] - receiver_type = "Uin" - start_time = "00:00:00" - end_time = "23:59:59" + notice_content_id = "noticetemplate-b417f32a-bdf9-46c5-933e-28c23cd7a6b7" + start_time = "00:00:00" + end_time = "23:59:59" + } + + web_callbacks { + callback_type = "Http" + url = "example.com" + method = "POST" + notice_content_id = "noticetemplate-b417f32a-bdf9-46c5-933e-28c23cd7a6b7" + remind_type = 1 + } + + tags = { + createdBy = "terraform" } } ``` @@ -41,29 +50,35 @@ resource "tencentcloud_cls_alarm_notice" "alarm_notice" { The following arguments are supported: -* `name` - (Required, String) alarm notice name. -* `type` - (Required, String) notice type. -* `notice_receivers` - (Optional, List) notice receivers. +* `name` - (Required, String) Alarm notice name. +* `type` - (Required, String) Notice type. Value: Trigger, Recovery, All. +* `notice_receivers` - (Optional, List) Notice receivers. * `tags` - (Optional, Map) Tag description list. -* `web_callbacks` - (Optional, List) callback info. +* `web_callbacks` - (Optional, List) Callback info. The `notice_receivers` object supports the following: -* `receiver_channels` - (Required, Set) receiver channels, Email,Sms,WeChat or Phone. -* `receiver_ids` - (Required, Set) receiver id. -* `receiver_type` - (Required, String) receiver type, Uin or Group. -* `end_time` - (Optional, String) end time allowed to receive messages. -* `index` - (Optional, Int) index. -* `start_time` - (Optional, String) start time allowed to receive messages. +* `receiver_channels` - (Required, Set) Receiver channels, Value: Email, Sms, WeChat, Phone. +* `receiver_ids` - (Required, Set) Receiver id list. +* `receiver_type` - (Required, String) Receiver type, Uin or Group. +* `end_time` - (Optional, String) End time allowed to receive messages. +* `index` - (Optional, Int) Index. The input parameter is invalid, but the output parameter is valid. +* `notice_content_id` - (Optional, String) Notice content ID. +* `start_time` - (Optional, String) Start time allowed to receive messages. The `web_callbacks` object supports the following: -* `callback_type` - (Required, String) callback type, WeCom or Http. -* `url` - (Required, String) callback url. -* `body` - (Optional, String) abandoned. -* `headers` - (Optional, Set) abandoned. -* `index` - (Optional, Int) index. +* `callback_type` - (Required, String) Callback type, Values: Http, WeCom, DingTalk, Lark. +* `url` - (Required, String) Callback url. +* `body` - (Optional, String, **Deprecated**) This parameter is deprecated. Please use `notice_content_id`. Request body. +* `headers` - (Optional, Set, **Deprecated**) This parameter is deprecated. Please use `notice_content_id`. Request headers. +* `index` - (Optional, Int) Index. The input parameter is invalid, but the output parameter is valid. * `method` - (Optional, String) Method, POST or PUT. +* `mobiles` - (Optional, Set) Telephone list. +* `notice_content_id` - (Optional, String) Notice content ID. +* `remind_type` - (Optional, Int) Remind type. 0: Do not remind; 1: Specified person; 2: Everyone. +* `user_ids` - (Optional, Set) User ID list. +* `web_callback_id` - (Optional, String) Integration configuration ID. ## Attributes Reference @@ -75,9 +90,9 @@ In addition to all arguments above, the following attributes are exported: ## Import -cls alarm_notice can be imported using the id, e.g. +cls alarm notice can be imported using the id, e.g. ``` -terraform import tencentcloud_cls_alarm_notice.alarm_notice alarm_notice_id +terraform import tencentcloud_cls_alarm_notice.example notice-19076f96-0f9a-4206-b308-b478737cab66 ``` diff --git a/website/docs/r/cls_notice_content.html.markdown b/website/docs/r/cls_notice_content.html.markdown index 56eee10966..f0c9706789 100644 --- a/website/docs/r/cls_notice_content.html.markdown +++ b/website/docs/r/cls_notice_content.html.markdown @@ -49,7 +49,7 @@ The following arguments are supported: The `notice_contents` object supports the following: -* `type` - (Required, String) Channel type. Email: Email; Sms: SMS; WeChat: WeChat; Phone: Telephone; WeCom: Enterprise WeChat; DingTalk: DingTalk; Lark: Feishu; HTTP: Custom callback. +* `type` - (Required, String) Channel type. Email: Email; Sms: SMS; WeChat: WeChat; Phone: Telephone; WeCom: Enterprise WeChat; DingTalk: DingTalk; Lark: Feishu; Http: Custom callback. * `recovery_content` - (Optional, List) Template for Alarm Recovery Notification Content. * `trigger_content` - (Optional, List) Alarm triggered notification content template.