From cd466efc083e58b7d96f23a686cd8e951b2d81e0 Mon Sep 17 00:00:00 2001 From: Diego Bonfigli Date: Mon, 7 Aug 2023 17:18:39 +0200 Subject: [PATCH 1/2] feat(notification channel): add allow_insecure_connections field to webhook notification channels --- ...ig_monitor_notification_channel_webhook.go | 10 +++++++++ ...nitor_notification_channel_webhook_test.go | 21 +++++++++++++++++++ ...dig_secure_notification_channel_webhook.go | 10 +++++++++ ...ecure_notification_channel_webhook_test.go | 21 +++++++++++++++++++ .../r/monitor_notification_channel_webhook.md | 2 ++ .../r/secure_notification_channel_webhook.md | 2 ++ 6 files changed, 66 insertions(+) diff --git a/sysdig/resource_sysdig_monitor_notification_channel_webhook.go b/sysdig/resource_sysdig_monitor_notification_channel_webhook.go index 2649e2cd..b294d33f 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_webhook.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_webhook.go @@ -40,6 +40,11 @@ func resourceSysdigMonitorNotificationChannelWebhook() *schema.Resource { Type: schema.TypeMap, Optional: true, }, + "allow_insecure_connections": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, }), } } @@ -147,6 +152,8 @@ func monitorNotificationChannelWebhookFromResourceData(d *schema.ResourceData, t nc.Type = NOTIFICATION_CHANNEL_TYPE_WEBHOOK nc.Options.Url = d.Get("url").(string) nc.Options.AdditionalHeaders = d.Get("additional_headers").(map[string]interface{}) + allowInsecureConnections := d.Get("allow_insecure_connections").(bool) + nc.Options.AllowInsecureConnections = &allowInsecureConnections return } @@ -158,6 +165,9 @@ func monitorNotificationChannelWebhookToResourceData(nc *v2.NotificationChannel, _ = d.Set("url", nc.Options.Url) _ = d.Set("additional_headers", nc.Options.AdditionalHeaders) + if nc.Options.AllowInsecureConnections != nil { + _ = d.Set("allow_insecure_connections", *nc.Options.AllowInsecureConnections) + } return } diff --git a/sysdig/resource_sysdig_monitor_notification_channel_webhook_test.go b/sysdig/resource_sysdig_monitor_notification_channel_webhook_test.go index 10a7d71a..872baa01 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_webhook_test.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_webhook_test.go @@ -48,6 +48,14 @@ func TestAccMonitorNotificationChannelWebhook(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + Config: monitorNotificationChannelWebhookSharedWithWithAllowInsecureConnections(rText()), + }, + { + ResourceName: "sysdig_monitor_notification_channel_webhook.sample-webhook4", + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -91,3 +99,16 @@ func monitorNotificationChannelWebhookSharedWithCurrentTeam(name string) string send_test_notification = false }`, name) } + +func monitorNotificationChannelWebhookSharedWithWithAllowInsecureConnections(name string) string { + return fmt.Sprintf(` + resource "sysdig_monitor_notification_channel_webhook" "sample-webhook4" { + name = "Example Channel %s - Webhook With Allow Insecure Connections" + enabled = true + allow_insecure_connections = true + url = "https://example.com/" + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false + }`, name) +} diff --git a/sysdig/resource_sysdig_secure_notification_channel_webhook.go b/sysdig/resource_sysdig_secure_notification_channel_webhook.go index 283caaa6..81bf7c61 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_webhook.go +++ b/sysdig/resource_sysdig_secure_notification_channel_webhook.go @@ -40,6 +40,11 @@ func resourceSysdigSecureNotificationChannelWebhook() *schema.Resource { Type: schema.TypeMap, Optional: true, }, + "allow_insecure_connections": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, }), } } @@ -146,6 +151,8 @@ func secureNotificationChannelWebhookFromResourceData(d *schema.ResourceData, te nc.Type = NOTIFICATION_CHANNEL_TYPE_WEBHOOK nc.Options.Url = d.Get("url").(string) nc.Options.AdditionalHeaders = d.Get("additional_headers").(map[string]interface{}) + allowInsecureConnections := d.Get("allow_insecure_connections").(bool) + nc.Options.AllowInsecureConnections = &allowInsecureConnections return } @@ -157,6 +164,9 @@ func secureNotificationChannelWebhookToResourceData(nc *v2.NotificationChannel, _ = d.Set("url", nc.Options.Url) _ = d.Set("additional_headers", nc.Options.AdditionalHeaders) + if nc.Options.AllowInsecureConnections != nil { + _ = d.Set("allow_insecure_connections", *nc.Options.AllowInsecureConnections) + } return } diff --git a/sysdig/resource_sysdig_secure_notification_channel_webhook_test.go b/sysdig/resource_sysdig_secure_notification_channel_webhook_test.go index 292ccf29..34204ab2 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_webhook_test.go +++ b/sysdig/resource_sysdig_secure_notification_channel_webhook_test.go @@ -41,6 +41,14 @@ func TestAccSecureNotificationChannelWebhook(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + Config: secureNotificationChannelWebhookSharedWithAllowInsecureConnections(rText()), + }, + { + ResourceName: "sysdig_secure_notification_channel_webhook.sample-webhook4", + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -69,3 +77,16 @@ func secureNotificationChannelWebhookSharedWithCurrentTeam(name string) string { send_test_notification = false }`, name) } + +func secureNotificationChannelWebhookSharedWithAllowInsecureConnections(name string) string { + return fmt.Sprintf(` + resource "sysdig_secure_notification_channel_webhook" "sample-webhook4" { + name = "Example Channel %s - Webhook With Allow Insecure Connections" + enabled = true + allow_insecure_connections = true + url = "https://example.com/" + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false + }`, name) +} diff --git a/website/docs/r/monitor_notification_channel_webhook.md b/website/docs/r/monitor_notification_channel_webhook.md index 7ac96b63..b09243f2 100644 --- a/website/docs/r/monitor_notification_channel_webhook.md +++ b/website/docs/r/monitor_notification_channel_webhook.md @@ -44,6 +44,8 @@ resource "sysdig_monitor_notification_channel_webhook" "sample-webhook" { * `additional_headers` - (Optional) Key value list of custom headers. +* `allow_insecure_connections` - (Optional) Whether to skip TLS verification. Default: `false`. + ## Attributes Reference In addition to all arguments above, the following attributes are exported: diff --git a/website/docs/r/secure_notification_channel_webhook.md b/website/docs/r/secure_notification_channel_webhook.md index 874a6ca4..7913ff58 100644 --- a/website/docs/r/secure_notification_channel_webhook.md +++ b/website/docs/r/secure_notification_channel_webhook.md @@ -44,6 +44,8 @@ resource "sysdig_secure_notification_channel_webhook" "sample-webhook" { * `additional_headers` - (Optional) Key value list of custom headers. +* `allow_insecure_connections` - (Optional) Whether to skip TLS verification. Default: `false`. + ## Attributes Reference In addition to all arguments above, the following attributes are exported: From ef7c8ee72d8b5900134d000a42938fc475251c93 Mon Sep 17 00:00:00 2001 From: Diego Bonfigli Date: Mon, 7 Aug 2023 17:35:33 +0200 Subject: [PATCH 2/2] feat(notification channel): add custom_data field to webhook notification channels --- sysdig/internal/client/v2/model.go | 4 +-- ...ig_monitor_notification_channel_webhook.go | 6 ++++ ...nitor_notification_channel_webhook_test.go | 28 +++++++++++++++++-- ...dig_secure_notification_channel_webhook.go | 6 ++++ ...ecure_notification_channel_webhook_test.go | 24 ++++++++++++++++ .../r/monitor_notification_channel_webhook.md | 19 +++++++++---- .../r/secure_notification_channel_webhook.md | 19 +++++++++---- 7 files changed, 90 insertions(+), 16 deletions(-) diff --git a/sysdig/internal/client/v2/model.go b/sysdig/internal/client/v2/model.go index e7f5db0d..ec8c53ef 100644 --- a/sysdig/internal/client/v2/model.go +++ b/sysdig/internal/client/v2/model.go @@ -116,13 +116,13 @@ type NotificationChannelOptions struct { ServiceName string `json:"serviceName,omitempty"` // Type: PagerDuty AdditionalHeaders map[string]interface{} `json:"additionalHeaders,omitempty"` // Type: Webhook, prometheus alert manager, custom webhook, ibm function Region string `json:"region,omitempty"` // Type: OpsGenie - AllowInsecureConnections *bool `json:"allowInsecureConnections,omitempty"` // Type: prometheus alert manager, custom webhook + AllowInsecureConnections *bool `json:"allowInsecureConnections,omitempty"` // Type: prometheus alert manager, custom webhook, Webhook TeamId int `json:"teamId,omitempty"` // Type: team email HttpMethod string `json:"httpMethod,omitempty"` // Type: custom webhook MonitorTemplate string `json:"monitorTemplate,omitempty"` // Type: custom webhook InstanceId string `json:"instanceId,omitempty"` // Type: ibm event notification IbmFunctionType string `json:"ibmFunctionType,omitempty"` // Type: ibm event function - CustomData map[string]interface{} `json:"customData,omitempty"` // Type: ibm function + CustomData map[string]interface{} `json:"customData,omitempty"` // Type: ibm function, Webhook TemplateConfiguration []NotificationChannelTemplateConfiguration `json:"templateConfiguration,omitempty"` NotifyOnOk bool `json:"notifyOnOk"` diff --git a/sysdig/resource_sysdig_monitor_notification_channel_webhook.go b/sysdig/resource_sysdig_monitor_notification_channel_webhook.go index b294d33f..c8b221b6 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_webhook.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_webhook.go @@ -45,6 +45,10 @@ func resourceSysdigMonitorNotificationChannelWebhook() *schema.Resource { Optional: true, Default: false, }, + "custom_data": { + Type: schema.TypeMap, + Optional: true, + }, }), } } @@ -152,6 +156,7 @@ func monitorNotificationChannelWebhookFromResourceData(d *schema.ResourceData, t nc.Type = NOTIFICATION_CHANNEL_TYPE_WEBHOOK nc.Options.Url = d.Get("url").(string) nc.Options.AdditionalHeaders = d.Get("additional_headers").(map[string]interface{}) + nc.Options.CustomData = d.Get("custom_data").(map[string]interface{}) allowInsecureConnections := d.Get("allow_insecure_connections").(bool) nc.Options.AllowInsecureConnections = &allowInsecureConnections return @@ -165,6 +170,7 @@ func monitorNotificationChannelWebhookToResourceData(nc *v2.NotificationChannel, _ = d.Set("url", nc.Options.Url) _ = d.Set("additional_headers", nc.Options.AdditionalHeaders) + _ = d.Set("custom_data", nc.Options.CustomData) if nc.Options.AllowInsecureConnections != nil { _ = d.Set("allow_insecure_connections", *nc.Options.AllowInsecureConnections) } diff --git a/sysdig/resource_sysdig_monitor_notification_channel_webhook_test.go b/sysdig/resource_sysdig_monitor_notification_channel_webhook_test.go index 872baa01..10441b1e 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_webhook_test.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_webhook_test.go @@ -49,13 +49,21 @@ func TestAccMonitorNotificationChannelWebhook(t *testing.T) { ImportStateVerify: true, }, { - Config: monitorNotificationChannelWebhookSharedWithWithAllowInsecureConnections(rText()), + Config: monitorNotificationChannelWebhookSharedWithAllowInsecureConnections(rText()), }, { ResourceName: "sysdig_monitor_notification_channel_webhook.sample-webhook4", ImportState: true, ImportStateVerify: true, }, + { + Config: monitorNotificationChannelWebhookSharedWithCustomData(rText()), + }, + { + ResourceName: "sysdig_monitor_notification_channel_webhook.sample-webhook5", + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -100,7 +108,7 @@ func monitorNotificationChannelWebhookSharedWithCurrentTeam(name string) string }`, name) } -func monitorNotificationChannelWebhookSharedWithWithAllowInsecureConnections(name string) string { +func monitorNotificationChannelWebhookSharedWithAllowInsecureConnections(name string) string { return fmt.Sprintf(` resource "sysdig_monitor_notification_channel_webhook" "sample-webhook4" { name = "Example Channel %s - Webhook With Allow Insecure Connections" @@ -112,3 +120,19 @@ func monitorNotificationChannelWebhookSharedWithWithAllowInsecureConnections(nam send_test_notification = false }`, name) } + +func monitorNotificationChannelWebhookSharedWithCustomData(name string) string { + return fmt.Sprintf(` + resource "sysdig_monitor_notification_channel_webhook" "sample-webhook5" { + name = "Example Channel %s - Webhook With Custom Data" + enabled = true + url = "https://example.com/" + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false + custom_data = { + "data1": "value1" + "data2": "value2" + } + }`, name) +} diff --git a/sysdig/resource_sysdig_secure_notification_channel_webhook.go b/sysdig/resource_sysdig_secure_notification_channel_webhook.go index 81bf7c61..981e83cd 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_webhook.go +++ b/sysdig/resource_sysdig_secure_notification_channel_webhook.go @@ -45,6 +45,10 @@ func resourceSysdigSecureNotificationChannelWebhook() *schema.Resource { Optional: true, Default: false, }, + "custom_data": { + Type: schema.TypeMap, + Optional: true, + }, }), } } @@ -151,6 +155,7 @@ func secureNotificationChannelWebhookFromResourceData(d *schema.ResourceData, te nc.Type = NOTIFICATION_CHANNEL_TYPE_WEBHOOK nc.Options.Url = d.Get("url").(string) nc.Options.AdditionalHeaders = d.Get("additional_headers").(map[string]interface{}) + nc.Options.CustomData = d.Get("custom_data").(map[string]interface{}) allowInsecureConnections := d.Get("allow_insecure_connections").(bool) nc.Options.AllowInsecureConnections = &allowInsecureConnections return @@ -164,6 +169,7 @@ func secureNotificationChannelWebhookToResourceData(nc *v2.NotificationChannel, _ = d.Set("url", nc.Options.Url) _ = d.Set("additional_headers", nc.Options.AdditionalHeaders) + _ = d.Set("custom_data", nc.Options.CustomData) if nc.Options.AllowInsecureConnections != nil { _ = d.Set("allow_insecure_connections", *nc.Options.AllowInsecureConnections) } diff --git a/sysdig/resource_sysdig_secure_notification_channel_webhook_test.go b/sysdig/resource_sysdig_secure_notification_channel_webhook_test.go index 34204ab2..5d73ff17 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_webhook_test.go +++ b/sysdig/resource_sysdig_secure_notification_channel_webhook_test.go @@ -49,6 +49,14 @@ func TestAccSecureNotificationChannelWebhook(t *testing.T) { ImportState: true, ImportStateVerify: true, }, + { + Config: secureNotificationChannelWebhookSharedWithCustomData(rText()), + }, + { + ResourceName: "sysdig_secure_notification_channel_webhook.sample-webhook5", + ImportState: true, + ImportStateVerify: true, + }, }, }) } @@ -90,3 +98,19 @@ func secureNotificationChannelWebhookSharedWithAllowInsecureConnections(name str send_test_notification = false }`, name) } + +func secureNotificationChannelWebhookSharedWithCustomData(name string) string { + return fmt.Sprintf(` + resource "sysdig_secure_notification_channel_webhook" "sample-webhook5" { + name = "Example Channel %s - Webhook With Custom Data" + enabled = true + url = "https://example.com/" + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false + custom_data = { + "data1": "value1" + "data2": "value2" + } + }`, name) +} diff --git a/website/docs/r/monitor_notification_channel_webhook.md b/website/docs/r/monitor_notification_channel_webhook.md index b09243f2..38b8f089 100644 --- a/website/docs/r/monitor_notification_channel_webhook.md +++ b/website/docs/r/monitor_notification_channel_webhook.md @@ -16,12 +16,17 @@ Creates a Sysdig Monitor Notification Channel of type Webhook. ```terraform resource "sysdig_monitor_notification_channel_webhook" "sample-webhook" { - name = "Example Channel - Webhook" - enabled = true - url = "localhost:8080" - notify_when_ok = false - notify_when_resolved = false - send_test_notification = false + name = "Example Channel - Webhook" + enabled = true + url = "localhost:8080" + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false + + custom_data = { + "data1": "value1" + "data2": "value2" + } } ``` @@ -31,6 +36,8 @@ resource "sysdig_monitor_notification_channel_webhook" "sample-webhook" { * `url` - (Required) URL to send the event. +* `custom_data` - (Optional) Key value list of additional data you want to attach to the alert notification. + * `enabled` - (Optional) If false, the channel will not emit notifications. Default is true. * `notify_when_ok` - (Optional) Send a new notification when the alert condition is diff --git a/website/docs/r/secure_notification_channel_webhook.md b/website/docs/r/secure_notification_channel_webhook.md index 7913ff58..0ba8beea 100644 --- a/website/docs/r/secure_notification_channel_webhook.md +++ b/website/docs/r/secure_notification_channel_webhook.md @@ -16,12 +16,17 @@ Creates a Sysdig Secure Notification Channel of type Webhook. ```terraform resource "sysdig_secure_notification_channel_webhook" "sample-webhook" { - name = "Example Channel - Webhook" - enabled = true - url = "localhost:8080" - notify_when_ok = false - notify_when_resolved = false - send_test_notification = false + name = "Example Channel - Webhook" + enabled = true + url = "localhost:8080" + notify_when_ok = false + notify_when_resolved = false + send_test_notification = false + + custom_data = { + "data1": "value1" + "data2": "value2" + } } ``` @@ -31,6 +36,8 @@ resource "sysdig_secure_notification_channel_webhook" "sample-webhook" { * `url` - (Required) URL to send the event. +* `custom_data` - (Optional) Key value list of additional data you want to attach to the alert notification. + * `enabled` - (Optional) If false, the channel will not emit notifications. Default is true. * `notify_when_ok` - (Optional) Send a new notification when the alert condition is