Skip to content

Commit bf4e4b0

Browse files
akahenrydbonf
andauthored
fix(notification-channels): add support to Slack private channels (#634)
* feat(slack notification channel) support slack private channel --------- Co-authored-by: Diego Bonfigli <diego.bonfigli@sysdig.com>
1 parent 320911a commit bf4e4b0

11 files changed

+113
-14
lines changed

sysdig/data_source_sysdig_monitor_notification_channel_slack.go

+8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ func dataSourceSysdigMonitorNotificationChannelSlack() *schema.Resource {
2929
Type: schema.TypeString,
3030
Computed: true,
3131
},
32+
"is_private_channel": {
33+
Type: schema.TypeBool,
34+
Computed: true,
35+
},
36+
"private_channel_url": {
37+
Type: schema.TypeString,
38+
Computed: true,
39+
},
3240
"show_section_runbook_links": {
3341
Type: schema.TypeBool,
3442
Computed: true,

sysdig/data_source_sysdig_secure_notification_channel_slack.go

+8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ func dataSourceSysdigSecureNotificationChannelSlack() *schema.Resource {
2929
Type: schema.TypeString,
3030
Computed: true,
3131
},
32+
"is_private_channel": {
33+
Type: schema.TypeBool,
34+
Computed: true,
35+
},
36+
"private_channel_url": {
37+
Type: schema.TypeString,
38+
Computed: true,
39+
},
3240
"template_version": {
3341
Type: schema.TypeString,
3442
Computed: true,

sysdig/internal/client/v2/model.go

+2
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ type NotificationChannelOptions struct {
121121
RoutingKey string `json:"routingKey,omitempty"` // Type: VictorOps
122122
Url string `json:"url,omitempty"` // Type: OpsGenie, Webhook, Slack, google chat, prometheus alert manager, custom webhook, ms teams
123123
Channel string `json:"channel,omitempty"` // Type: Slack
124+
PrivateChannel bool `json:"privateChannel,omitempty"` // Type: Slack
125+
PrivateChannelUrl string `json:"privateChannelUrl,omitempty"` // Type: Slack
124126
Account string `json:"account,omitempty"` // Type: PagerDuty
125127
ServiceKey string `json:"serviceKey,omitempty"` // Type: PagerDuty
126128
ServiceName string `json:"serviceName,omitempty"` // Type: PagerDuty

sysdig/resource_sysdig_monitor_notification_channel_slack.go

+15
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ func resourceSysdigMonitorNotificationChannelSlack() *schema.Resource {
4040
Type: schema.TypeString,
4141
Required: true,
4242
},
43+
"is_private_channel": {
44+
Type: schema.TypeBool,
45+
Optional: true,
46+
Default: false,
47+
ForceNew: true,
48+
},
49+
"private_channel_url": {
50+
Type: schema.TypeString,
51+
Optional: true,
52+
ForceNew: true,
53+
},
4354
"show_section_runbook_links": {
4455
Type: schema.TypeBool,
4556
Optional: true,
@@ -193,6 +204,8 @@ func monitorNotificationChannelSlackFromResourceData(d *schema.ResourceData, tea
193204
nc.Type = NOTIFICATION_CHANNEL_TYPE_SLACK
194205
nc.Options.Url = d.Get("url").(string)
195206
nc.Options.Channel = d.Get("channel").(string)
207+
nc.Options.PrivateChannel = d.Get("is_private_channel").(bool)
208+
nc.Options.PrivateChannelUrl = d.Get("private_channel_url").(string)
196209
nc.Options.TemplateConfiguration = []v2.NotificationChannelTemplateConfiguration{
197210
{
198211
TemplateKey: "SLACK_MONITOR_ALERT_NOTIFICATION_TEMPLATE_METADATA_v1",
@@ -244,6 +257,8 @@ func monitorNotificationChannelSlackToResourceData(nc *v2.NotificationChannel, d
244257

245258
_ = d.Set("url", nc.Options.Url)
246259
_ = d.Set("channel", nc.Options.Channel)
260+
_ = d.Set("is_private_channel", nc.Options.PrivateChannel)
261+
_ = d.Set("private_channel_url", nc.Options.PrivateChannelUrl)
247262

248263
runbookLinks := true
249264
eventDetails := true

sysdig/resource_sysdig_monitor_notification_channel_slack_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ func TestAccMonitorNotificationChannelSlack(t *testing.T) {
4343
ImportState: true,
4444
ImportStateVerify: true,
4545
},
46+
{
47+
Config: monitorNotificationChannelSlackSharedWithPrivateChannel(rText()),
48+
},
49+
{
50+
ResourceName: "sysdig_monitor_notification_channel_slack.sample-slack-private",
51+
ImportState: true,
52+
ImportStateVerify: true,
53+
},
4654
},
4755
})
4856
}
@@ -90,3 +98,15 @@ resource "sysdig_monitor_notification_channel_slack" "sample-slack" {
9098
show_section_capturing_information = false
9199
}`, name)
92100
}
101+
102+
func monitorNotificationChannelSlackSharedWithPrivateChannel(name string) string {
103+
return fmt.Sprintf(`
104+
resource "sysdig_monitor_notification_channel_slack" "sample-slack-private" {
105+
name = "Example Channel %s - Slack"
106+
enabled = true
107+
url = "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX"
108+
channel = "#sysdig"
109+
is_private_channel = true
110+
private_channel_url = "https://app.slack.com/client/XXXXXXXX/XXXXXXXX"
111+
}`, name)
112+
}

sysdig/resource_sysdig_secure_notification_channel_slack.go

+15
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ func resourceSysdigSecureNotificationChannelSlack() *schema.Resource {
4141
Type: schema.TypeString,
4242
Required: true,
4343
},
44+
"is_private_channel": {
45+
Type: schema.TypeBool,
46+
Optional: true,
47+
Default: false,
48+
ForceNew: true,
49+
},
50+
"private_channel_url": {
51+
Type: schema.TypeString,
52+
Optional: true,
53+
ForceNew: true,
54+
},
4455
"template_version": {
4556
Type: schema.TypeString,
4657
Optional: true,
@@ -163,6 +174,8 @@ func secureNotificationChannelSlackFromResourceData(d *schema.ResourceData, team
163174
nc.Type = NOTIFICATION_CHANNEL_TYPE_SLACK
164175
nc.Options.Url = d.Get("url").(string)
165176
nc.Options.Channel = d.Get("channel").(string)
177+
nc.Options.PrivateChannel = d.Get("is_private_channel").(bool)
178+
nc.Options.PrivateChannelUrl = d.Get("private_channel_url").(string)
166179

167180
setNotificationChannelSlackTemplateConfig(&nc, d)
168181

@@ -208,6 +221,8 @@ func secureNotificationChannelSlackToResourceData(nc *v2.NotificationChannel, d
208221

209222
_ = d.Set("url", nc.Options.Url)
210223
_ = d.Set("channel", nc.Options.Channel)
224+
_ = d.Set("is_private_channel", nc.Options.PrivateChannel)
225+
_ = d.Set("private_channel_url", nc.Options.PrivateChannelUrl)
211226

212227
err = getTemplateVersionFromNotificationChannelSlack(nc, d)
213228

sysdig/resource_sysdig_secure_notification_channel_slack_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ func TestAccSecureNotificationChannelSlack(t *testing.T) {
4848
ImportState: true,
4949
ImportStateVerify: true,
5050
},
51+
{
52+
Config: secureNotificationChannelSlackSharedWithPrivateChannel(rText()),
53+
},
54+
{
55+
ResourceName: "sysdig_secure_notification_channel_slack.sample-slack-private",
56+
ImportState: true,
57+
ImportStateVerify: true,
58+
},
5159
},
5260
})
5361
}
@@ -89,3 +97,15 @@ resource "sysdig_secure_notification_channel_slack" "sample-slack" {
8997
template_version = "%s"
9098
}`, name, version)
9199
}
100+
101+
func secureNotificationChannelSlackSharedWithPrivateChannel(name string) string {
102+
return fmt.Sprintf(`
103+
resource "sysdig_secure_notification_channel_slack" "sample-slack-private" {
104+
name = "Example Channel %s - Slack"
105+
enabled = true
106+
url = "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX"
107+
channel = "#sysdig"
108+
is_private_channel = true
109+
private_channel_url = "https://app.slack.com/client/XXXXXXXX/XXXXXXXX"
110+
}`, name)
111+
}

website/docs/d/monitor_notification_channel_slack.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ data "sysdig_monitor_notification_channel_slack" "nc_slack" {
2929
In addition to all arguments above, the following attributes are exported:
3030

3131
* `id` - The Notification Channel ID.
32-
* `name` - The Notification Channel Name.
33-
* `url` - URL of the Slack.
34-
* `channel` - Channel name from this Slack.
32+
* `url` - URL of the Slack webhook.
33+
* `channel` - Name of the Slack channel.
34+
* `is_private_channel` - Whether the Slack Channel has been marked as private or not.
35+
* `private_channel_url` - The channel URL, i.e. the link that is referencing the channel (not to be confused with the webhook url), if the channel is private.
3536
* `show_section_runbook_links` - Whether to include the runbook links section in the Slack messages.
3637
* `show_section_event_details` - Whether to include the event details section in the Slack messages.
3738
* `show_section_user_defined_content` - Whether to include the user defined section in the Slack messages.
@@ -41,7 +42,6 @@ In addition to all arguments above, the following attributes are exported:
4142
* `show_section_capturing_information` - Whether to include the capturing information section in the Slack messages.
4243
* `enabled` - Whether the Notification Channel is active or not.
4344
* `notify_when_ok` - Whether the Notification Channel sends a notification when the condition is no longer triggered.
44-
* `notify_when_resolved` - Whether the Notification Channel sends a notification if it's manually acknowledged by a
45-
user.
45+
* `notify_when_resolved` - Whether the Notification Channel sends a notification if it's manually acknowledged by a user.
4646
* `version` - The version of the Notification Channel.
4747
* `send_test_notification` - Whether the Notification Channel has enabled the test notification.

website/docs/d/secure_notification_channel_slack.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ data "sysdig_secure_notification_channel_slack" "nc_slack" {
2929
In addition to all arguments above, the following attributes are exported:
3030

3131
* `id` - The Notification Channel ID.
32-
* `name` - The Notification Channel Name.
33-
* `url` - URL of the Slack.
34-
* `channel` - Channel name from this Slack.* `template_version` - The notification template version to use to create notifications.
32+
* `url` - URL of the Slack webhook.
33+
* `channel` - Name of the Slack channel.
34+
* `is_private_channel` - Whether the Slack Channel has been marked as private or not.
35+
* `private_channel_url` - The channel URL, i.e. the link that is referencing the channel (not to be confused with the webhook url), if the channel is private.
36+
* `template_version` - The notification template version to use to create notifications.
3537
* `enabled` - Whether the Notification Channel is active or not.
3638
* `notify_when_ok` - Whether the Notification Channel sends a notification when the condition is no longer triggered.
37-
* `notify_when_resolved` - Whether the Notification Channel sends a notification if it's manually acknowledged by a
38-
user.
39+
* `notify_when_resolved` - Whether the Notification Channel sends a notification if it's manually acknowledged by a user.
3940
* `version` - The version of the Notification Channel.
4041
* `send_test_notification` - Whether the Notification Channel has enabled the test notification.

website/docs/r/monitor_notification_channel_slack.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ resource "sysdig_monitor_notification_channel_slack" "sample-slack" {
2020
enabled = true
2121
url = "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX"
2222
channel = "#sysdig"
23+
is_private_channel = false
2324
notify_when_ok = false
2425
notify_when_resolved = false
2526
}
@@ -29,7 +30,7 @@ resource "sysdig_monitor_notification_channel_slack" "sample-slack" {
2930

3031
* `name` - (Required) The name of the Notification Channel. Must be unique.
3132

32-
* `url` - (Required) URL of the Slack.
33+
* `url` - (Required) URL of the Slack webhook.
3334

3435
* `show_section_runbook_links` - (Optional) Whether to include the runbook links section in the Slack messages. Default: true.
3536

@@ -45,7 +46,11 @@ resource "sysdig_monitor_notification_channel_slack" "sample-slack" {
4546

4647
* `show_section_capturing_information` - (Optional) Whether to include the capturing information section in the Slack messages. Default: true.
4748

48-
* `channel` - (Required) Channel name from this Slack.
49+
* `channel` - (Required) Name of the Slack channel. **NOTE**: If the channel is private this field cannot be changed after creation.
50+
51+
* `is_private_channel` - (Optional, Forces new resource) If true, the Slack channel name will be visible only to the user that created this notification channel. Default: false.
52+
53+
* `private_channel_url` - (Optional, Forces new resource) The channel URL, i.e. the link that is referencing the channel (not to be confused with the webhook url). Can be set only if the channel is private.
4954

5055
* `enabled` - (Optional) If false, the channel will not emit notifications. Default is true.
5156

website/docs/r/secure_notification_channel_slack.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ resource "sysdig_secure_notification_channel_slack" "sample-slack" {
2020
enabled = true
2121
url = "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX"
2222
channel = "#sysdig"
23+
is_private_channel = false
2324
notify_when_ok = false
2425
notify_when_resolved = false
2526
template_version = "v2"
@@ -30,9 +31,13 @@ resource "sysdig_secure_notification_channel_slack" "sample-slack" {
3031

3132
* `name` - (Required) The name of the Notification Channel. Must be unique.
3233

33-
* `url` - (Required) URL of the Slack.
34+
* `url` - (Required) URL of the Slack webhook.
3435

35-
* `channel` - (Required) Channel name from this Slack.
36+
* `channel` - (Required) Name of the Slack channel. **NOTE**: If the channel is private this field cannot be changed after creation.
37+
38+
* `is_private_channel` - (Optional, Forces new resource) If true, the Slack channel name will be visible only to the user that created this notification channel. Default: false.
39+
40+
* `private_channel_url` - (Optional, Forces new resource) The channel URL, i.e. the link that is referencing the channel (not to be confused with the webhook url). Can be set only if the channel is private.
3641

3742
* `enabled` - (Optional) If false, the channel will not emit notifications. Default is true.
3843

0 commit comments

Comments
 (0)