Skip to content

Commit ae298a8

Browse files
DenysChekirdaDenys Chekirda
andauthored
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 <[email protected]>
1 parent 31a53bb commit ae298a8

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

sysdig/internal/client/monitor/models.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,15 +155,16 @@ type usersListWrapper struct {
155155
// -------- Notification Channels --------
156156

157157
type NotificationChannelOptions struct {
158-
EmailRecipients []string `json:"emailRecipients,omitempty"` // Type: email
159-
SnsTopicARNs []string `json:"snsTopicARNs,omitempty"` // Type: SNS
160-
APIKey string `json:"apiKey,omitempty"` // Type: VictorOps
161-
RoutingKey string `json:"routingKey,omitempty"` // Type: VictorOps
162-
Url string `json:"url,omitempty"` // Type: OpsGenie, Webhook and Slack
163-
Channel string `json:"channel,omitempty"` // Type: Slack
164-
Account string `json:"account,omitempty"` // Type: PagerDuty
165-
ServiceKey string `json:"serviceKey,omitempty"` // Type: PagerDuty
166-
ServiceName string `json:"serviceName,omitempty"` // Type: PagerDuty
158+
EmailRecipients []string `json:"emailRecipients,omitempty"` // Type: email
159+
SnsTopicARNs []string `json:"snsTopicARNs,omitempty"` // Type: SNS
160+
APIKey string `json:"apiKey,omitempty"` // Type: VictorOps
161+
RoutingKey string `json:"routingKey,omitempty"` // Type: VictorOps
162+
Url string `json:"url,omitempty"` // Type: OpsGenie, Webhook and Slack
163+
Channel string `json:"channel,omitempty"` // Type: Slack
164+
Account string `json:"account,omitempty"` // Type: PagerDuty
165+
ServiceKey string `json:"serviceKey,omitempty"` // Type: PagerDuty
166+
ServiceName string `json:"serviceName,omitempty"` // Type: PagerDuty
167+
AdditionalHeaders map[string]interface{} `json:"additionalHeaders,omitempty"` // Type: Webhook
167168

168169
NotifyOnOk bool `json:"notifyOnOk"`
169170
NotifyOnResolve bool `json:"notifyOnResolve"`

sysdig/resource_sysdig_monitor_notification_channel_webhook.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ func resourceSysdigMonitorNotificationChannelWebhook() *schema.Resource {
3636
Type: schema.TypeString,
3737
Required: true,
3838
},
39+
"additional_headers": {
40+
Type: schema.TypeMap,
41+
Optional: true,
42+
},
3943
}),
4044
}
4145
}
@@ -131,6 +135,7 @@ func monitorNotificationChannelWebhookFromResourceData(d *schema.ResourceData) (
131135

132136
nc.Type = NOTIFICATION_CHANNEL_TYPE_WEBHOOK
133137
nc.Options.Url = d.Get("url").(string)
138+
nc.Options.AdditionalHeaders = d.Get("additional_headers").(map[string]interface{})
134139
return
135140
}
136141

@@ -141,5 +146,6 @@ func monitorNotificationChannelWebhookToResourceData(nc *monitor.NotificationCha
141146
}
142147

143148
d.Set("url", nc.Options.Url)
149+
d.Set("additional_headers", nc.Options.AdditionalHeaders)
144150
return
145151
}

sysdig/resource_sysdig_monitor_notification_channel_webhook_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ func TestAccMonitorNotificationChannelWebhook(t *testing.T) {
3535
ImportState: true,
3636
ImportStateVerify: true,
3737
},
38+
{
39+
Config: monitorNotificationChannelWebhookWithNameWithAdditionalheaders(rText()),
40+
},
3841
},
3942
})
4043
}
@@ -44,9 +47,24 @@ func monitorNotificationChannelWebhookWithName(name string) string {
4447
resource "sysdig_monitor_notification_channel_webhook" "sample-webhook" {
4548
name = "Example Channel %s - Webhook"
4649
enabled = true
47-
url = "http://1.1.1.1:8080"
50+
url = "https://example.com/"
4851
notify_when_ok = false
4952
notify_when_resolved = false
5053
send_test_notification = false
5154
}`, name)
5255
}
56+
57+
func monitorNotificationChannelWebhookWithNameWithAdditionalheaders(name string) string {
58+
return fmt.Sprintf(`
59+
resource "sysdig_monitor_notification_channel_webhook" "sample-webhook2" {
60+
name = "Example Channel %s - Webhook With Additional Headers"
61+
enabled = true
62+
url = "https://example.com/"
63+
notify_when_ok = false
64+
notify_when_resolved = false
65+
send_test_notification = false
66+
additional_headers = {
67+
"Webhook-Header": "TestHeader"
68+
}
69+
}`, name)
70+
}

website/docs/r/sysdig_monitor_notification_channel_webhook.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ resource "sysdig_monitor_notification_channel_webhook" "sample-webhook" {
4242
* `send_test_notification` - (Optional) Send an initial test notification to check
4343
if the notification channel is working. Default is false.
4444

45+
* `additional_headers` - (Optional) Key value list of custom headers.
46+
4547
## Attributes Reference
4648

4749
In addition to all arguments above, the following attributes are exported:

0 commit comments

Comments
 (0)