Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(notification channel): add fields to webhook notification channels #392

Merged
merged 2 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sysdig/internal/client/v2/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
16 changes: 16 additions & 0 deletions sysdig/resource_sysdig_monitor_notification_channel_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ func resourceSysdigMonitorNotificationChannelWebhook() *schema.Resource {
Type: schema.TypeMap,
Optional: true,
},
"allow_insecure_connections": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"custom_data": {
Type: schema.TypeMap,
Optional: true,
},
}),
}
}
Expand Down Expand Up @@ -147,6 +156,9 @@ 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
}

Expand All @@ -158,6 +170,10 @@ 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)
}

return
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ func TestAccMonitorNotificationChannelWebhook(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
{
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,
},
},
})
}
Expand Down Expand Up @@ -91,3 +107,32 @@ func monitorNotificationChannelWebhookSharedWithCurrentTeam(name string) string
send_test_notification = false
}`, name)
}

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"
enabled = true
allow_insecure_connections = true
url = "https://example.com/"
notify_when_ok = false
notify_when_resolved = false
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)
}
16 changes: 16 additions & 0 deletions sysdig/resource_sysdig_secure_notification_channel_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ func resourceSysdigSecureNotificationChannelWebhook() *schema.Resource {
Type: schema.TypeMap,
Optional: true,
},
"allow_insecure_connections": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"custom_data": {
Type: schema.TypeMap,
Optional: true,
},
}),
}
}
Expand Down Expand Up @@ -146,6 +155,9 @@ 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
}

Expand All @@ -157,6 +169,10 @@ 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)
}

return
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ func TestAccSecureNotificationChannelWebhook(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
{
Config: secureNotificationChannelWebhookSharedWithAllowInsecureConnections(rText()),
},
{
ResourceName: "sysdig_secure_notification_channel_webhook.sample-webhook4",
ImportState: true,
ImportStateVerify: true,
},
{
Config: secureNotificationChannelWebhookSharedWithCustomData(rText()),
},
{
ResourceName: "sysdig_secure_notification_channel_webhook.sample-webhook5",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -69,3 +85,32 @@ 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)
}

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)
}
21 changes: 15 additions & 6 deletions website/docs/r/monitor_notification_channel_webhook.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
```

Expand All @@ -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
Expand All @@ -44,6 +51,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:
Expand Down
21 changes: 15 additions & 6 deletions website/docs/r/secure_notification_channel_webhook.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
```

Expand All @@ -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
Expand All @@ -44,6 +51,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:
Expand Down
Loading