From ae298a874b7f95e572fecc50f09ddb62dbd71b03 Mon Sep 17 00:00:00 2001 From: DenysChekirda <68537888+DenysChekirda@users.noreply.github.com> Date: Tue, 5 Oct 2021 11:20:56 +0200 Subject: [PATCH] feat: Add support of custom headers for Webhook notifications (#124) * Added support of custom headers for Webhook notifications * Added description of the argument into docs * Added test for notification channel webhook with additional headers * Updated testacc for TestAccMonitorNotificationChannelWebhook Co-authored-by: Denys Chekirda --- sysdig/internal/client/monitor/models.go | 19 +++++++++--------- ...ig_monitor_notification_channel_webhook.go | 6 ++++++ ...nitor_notification_channel_webhook_test.go | 20 ++++++++++++++++++- ...ig_monitor_notification_channel_webhook.md | 2 ++ 4 files changed, 37 insertions(+), 10 deletions(-) diff --git a/sysdig/internal/client/monitor/models.go b/sysdig/internal/client/monitor/models.go index a69840bb..9eb04418 100644 --- a/sysdig/internal/client/monitor/models.go +++ b/sysdig/internal/client/monitor/models.go @@ -155,15 +155,16 @@ type usersListWrapper struct { // -------- Notification Channels -------- type NotificationChannelOptions struct { - EmailRecipients []string `json:"emailRecipients,omitempty"` // Type: email - SnsTopicARNs []string `json:"snsTopicARNs,omitempty"` // Type: SNS - APIKey string `json:"apiKey,omitempty"` // Type: VictorOps - RoutingKey string `json:"routingKey,omitempty"` // Type: VictorOps - Url string `json:"url,omitempty"` // Type: OpsGenie, Webhook and Slack - Channel string `json:"channel,omitempty"` // Type: Slack - Account string `json:"account,omitempty"` // Type: PagerDuty - ServiceKey string `json:"serviceKey,omitempty"` // Type: PagerDuty - ServiceName string `json:"serviceName,omitempty"` // Type: PagerDuty + EmailRecipients []string `json:"emailRecipients,omitempty"` // Type: email + SnsTopicARNs []string `json:"snsTopicARNs,omitempty"` // Type: SNS + APIKey string `json:"apiKey,omitempty"` // Type: VictorOps + RoutingKey string `json:"routingKey,omitempty"` // Type: VictorOps + Url string `json:"url,omitempty"` // Type: OpsGenie, Webhook and Slack + Channel string `json:"channel,omitempty"` // Type: Slack + Account string `json:"account,omitempty"` // Type: PagerDuty + ServiceKey string `json:"serviceKey,omitempty"` // Type: PagerDuty + ServiceName string `json:"serviceName,omitempty"` // Type: PagerDuty + AdditionalHeaders map[string]interface{} `json:"additionalHeaders,omitempty"` // Type: Webhook NotifyOnOk bool `json:"notifyOnOk"` NotifyOnResolve bool `json:"notifyOnResolve"` diff --git a/sysdig/resource_sysdig_monitor_notification_channel_webhook.go b/sysdig/resource_sysdig_monitor_notification_channel_webhook.go index 68b5cb5b..a099c288 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_webhook.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_webhook.go @@ -36,6 +36,10 @@ func resourceSysdigMonitorNotificationChannelWebhook() *schema.Resource { Type: schema.TypeString, Required: true, }, + "additional_headers": { + Type: schema.TypeMap, + Optional: true, + }, }), } } @@ -131,6 +135,7 @@ func monitorNotificationChannelWebhookFromResourceData(d *schema.ResourceData) ( nc.Type = NOTIFICATION_CHANNEL_TYPE_WEBHOOK nc.Options.Url = d.Get("url").(string) + nc.Options.AdditionalHeaders = d.Get("additional_headers").(map[string]interface{}) return } @@ -141,5 +146,6 @@ func monitorNotificationChannelWebhookToResourceData(nc *monitor.NotificationCha } d.Set("url", nc.Options.Url) + d.Set("additional_headers", nc.Options.AdditionalHeaders) return } diff --git a/sysdig/resource_sysdig_monitor_notification_channel_webhook_test.go b/sysdig/resource_sysdig_monitor_notification_channel_webhook_test.go index 1b4b06c8..1f45190c 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_webhook_test.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_webhook_test.go @@ -35,6 +35,9 @@ func TestAccMonitorNotificationChannelWebhook(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + Config: monitorNotificationChannelWebhookWithNameWithAdditionalheaders(rText()), + }, }, }) } @@ -44,9 +47,24 @@ func monitorNotificationChannelWebhookWithName(name string) string { resource "sysdig_monitor_notification_channel_webhook" "sample-webhook" { name = "Example Channel %s - Webhook" enabled = true - url = "http://1.1.1.1:8080" + url = "https://example.com/" notify_when_ok = false notify_when_resolved = false send_test_notification = false }`, name) } + +func monitorNotificationChannelWebhookWithNameWithAdditionalheaders(name string) string { + return fmt.Sprintf(` + resource "sysdig_monitor_notification_channel_webhook" "sample-webhook2" { + name = "Example Channel %s - Webhook With Additional Headers" + enabled = true + url = "https://example.com/" + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false + additional_headers = { + "Webhook-Header": "TestHeader" + } + }`, name) +} diff --git a/website/docs/r/sysdig_monitor_notification_channel_webhook.md b/website/docs/r/sysdig_monitor_notification_channel_webhook.md index be89a01a..0cfe1f8d 100644 --- a/website/docs/r/sysdig_monitor_notification_channel_webhook.md +++ b/website/docs/r/sysdig_monitor_notification_channel_webhook.md @@ -42,6 +42,8 @@ resource "sysdig_monitor_notification_channel_webhook" "sample-webhook" { * `send_test_notification` - (Optional) Send an initial test notification to check if the notification channel is working. Default is false. +* `additional_headers` - (Optional) Key value list of custom headers. + ## Attributes Reference In addition to all arguments above, the following attributes are exported: