From 33bbf5149848d97949567243c2e9b3a393d5695a Mon Sep 17 00:00:00 2001 From: Marko Simon Date: Fri, 12 Jan 2024 22:01:49 +0100 Subject: [PATCH 1/6] add telegram as alert action type --- ilert/resource_alert_action.go | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/ilert/resource_alert_action.go b/ilert/resource_alert_action.go index 08c350a..4720b53 100644 --- a/ilert/resource_alert_action.go +++ b/ilert/resource_alert_action.go @@ -561,7 +561,22 @@ func resourceAlertAction() *schema.Resource { }, }, }, - + "telegram": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + MinItems: 1, + ForceNew: true, + ConflictsWith: removeStringsFromSlice(alertActionTypesAll, ilert.ConnectorTypes.Telegram), + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "channel_id": { + Type: schema.TypeString, + Required: true, + }, + }, + }, + }, "created_at": { Type: schema.TypeString, Computed: true, @@ -960,6 +975,16 @@ func buildAlertAction(d *schema.ResourceData) (*ilert.AlertAction, error) { } } + if val, ok := d.GetOk("telegram"); ok { + vL := val.([]interface{}) + if len(vL) > 0 { + v := vL[0].(map[string]interface{}) + alertAction.Params = &ilert.AlertActionParamsTelegram{ + ChannelID: v["channel_id"].(string), + } + } + } + if val, ok := d.GetOk("alert_filter"); ok { vL := val.([]interface{}) if len(vL) > 0 { @@ -1237,6 +1262,12 @@ func resourceAlertActionRead(ctx context.Context, d *schema.ResourceData, m inte "service_ids": result.AlertAction.Params.ServiceIds, }, }) + case ilert.ConnectorTypes.Telegram: + d.Set("telegram", []interface{}{ + map[string]interface{}{ + "channel_id": result.AlertAction.Params.ChannelID, + }, + }) } alertFilter, err := flattenAlertActionAlertFilter(result.AlertAction.AlertFilter) From bb03956f00076cbb82831d9f9a01bd7d6fea9934 Mon Sep 17 00:00:00 2001 From: Marko Simon Date: Fri, 12 Jan 2024 22:05:15 +0100 Subject: [PATCH 2/6] add telegram type to docs --- website/docs/r/alert_action.html.markdown | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/website/docs/r/alert_action.html.markdown b/website/docs/r/alert_action.html.markdown index 29b03e4..bcee630 100644 --- a/website/docs/r/alert_action.html.markdown +++ b/website/docs/r/alert_action.html.markdown @@ -91,6 +91,7 @@ The following arguments are supported: - `dingtalk` - (Optional) A [dingtalk](#dingtalk-arguments) block. - `dingtalk_action` - (Optional) A [dingtalk_action](#dingtalk-action-arguments) block. - `automation_rule` - (Optional) An [automation_rule](#automation-rule-arguments) block. +- `telegram` - (Optional) An [telegram](#telegram-arguments) block. - `alert_filter` - (Optional) An [alert_filter](#alert-filter-arguments) block. #### Alert Source Arguments @@ -252,6 +253,12 @@ The following arguments are supported: - `resolve_incident` - (Optional, requires `template_id`) Determines whether an incident should be resolved or not. Default: `false` - `send_notification` - (Optional, requires `template_id`) Determines whether notifications should be sent or not. Default: `false` +#### Telegram Arguments + +> See [the Telegram integration documentation](https://docs.ilert.com/integrations/telegram) for more details. + +- `channel_id` - (Required) The Telegram channel id. + #### Alert Filter Arguments - `operator` - (Required) The operator to use for the filter. Allowed values are `AND` or `OR`. From 03e40d03a13caeae9acdd34ab48d7bdc9ff4e69a Mon Sep 17 00:00:00 2001 From: Marko Simon Date: Fri, 12 Jan 2024 22:06:47 +0100 Subject: [PATCH 3/6] edit changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 665f530..266f234 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 12.01.2024, Version 2.5.0 + +- feature/add-telegram-alert-action-type in [#80](https://github.com/iLert/terraform-provider-ilert/pull/80) + ## 05.01.2024, Version 2.4.1 - fix/status-page-theme-mode-field in [#79](https://github.com/iLert/terraform-provider-ilert/pull/79) From 88ab21b24de4f91bef45d12ac6909958275a4d7a Mon Sep 17 00:00:00 2001 From: Marko Simon Date: Fri, 12 Jan 2024 22:07:08 +0100 Subject: [PATCH 4/6] bump go sdk version --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 48d194f..0c0a4de 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.19 require ( github.com/hashicorp/terraform-plugin-sdk/v2 v2.25.0 - github.com/iLert/ilert-go/v3 v3.4.1 + github.com/iLert/ilert-go/v3 v3.5.0 ) require ( From 90b33e6806049827dc13e6d7ca92c9da565c970e Mon Sep 17 00:00:00 2001 From: Marko Simon Date: Sat, 13 Jan 2024 03:56:11 +0100 Subject: [PATCH 5/6] fix connector types --- ilert/resource_connector.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ilert/resource_connector.go b/ilert/resource_connector.go index d567a1a..caeff7f 100644 --- a/ilert/resource_connector.go +++ b/ilert/resource_connector.go @@ -15,7 +15,7 @@ import ( func resourceConnector() *schema.Resource { // include only type that schema supports - connectorTypesAll := removeStringsFromSlice(ilert.ConnectorTypesAll, ilert.ConnectorTypes.Email, ilert.ConnectorTypes.MicrosoftTeams, ilert.ConnectorTypes.MicrosoftTeamsBot, ilert.ConnectorTypes.ZoomChat, ilert.ConnectorTypes.ZoomMeeting, ilert.ConnectorTypes.Webex, ilert.ConnectorTypes.Slack, ilert.ConnectorTypes.Webhook, ilert.ConnectorTypes.Zapier, ilert.ConnectorTypes.DingTalkAction, ilert.ConnectorTypes.AutomationRule) + connectorTypesAll := removeStringsFromSlice(ilert.ConnectorTypesAll, ilert.ConnectorTypes.Email, ilert.ConnectorTypes.MicrosoftTeams, ilert.ConnectorTypes.MicrosoftTeamsBot, ilert.ConnectorTypes.ZoomChat, ilert.ConnectorTypes.ZoomMeeting, ilert.ConnectorTypes.Webex, ilert.ConnectorTypes.Slack, ilert.ConnectorTypes.Webhook, ilert.ConnectorTypes.Zapier, ilert.ConnectorTypes.DingTalkAction, ilert.ConnectorTypes.AutomationRule, ilert.ConnectorTypes.Telegram) return &schema.Resource{ Schema: map[string]*schema.Schema{ "name": { From 6eda070abbc72c8ae5955cd6a311e781729f4cf3 Mon Sep 17 00:00:00 2001 From: Marko Simon Date: Sat, 13 Jan 2024 17:55:48 +0100 Subject: [PATCH 6/6] upgrade to new go sdk version --- go.sum | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.sum b/go.sum index 4a4c6c6..a2fd566 100644 --- a/go.sum +++ b/go.sum @@ -103,8 +103,8 @@ github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ= github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= -github.com/iLert/ilert-go/v3 v3.4.1 h1:kXofKIkU4b/Mm2fG3INnJSz6g5XATgQwY/ExmsEX0u0= -github.com/iLert/ilert-go/v3 v3.4.1/go.mod h1:xHJ8qdmthK4HExcQOd3V5JARed/EBKTdX86MqrJ1yJ0= +github.com/iLert/ilert-go/v3 v3.5.0 h1:lIQqtO8BosDNri1ZkTTlG6kYOSDepdSygfCx00EMyIw= +github.com/iLert/ilert-go/v3 v3.5.0/go.mod h1:xHJ8qdmthK4HExcQOd3V5JARed/EBKTdX86MqrJ1yJ0= github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=