Skip to content

fix(notification-channels): add support to Slack private channels #634

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

Merged
merged 4 commits into from
Apr 29, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ func dataSourceSysdigMonitorNotificationChannelSlack() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"is_private_channel": {
Type: schema.TypeBool,
Computed: true,
},
"private_channel_url": {
Type: schema.TypeString,
Computed: true,
},
"show_section_runbook_links": {
Type: schema.TypeBool,
Computed: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ func dataSourceSysdigSecureNotificationChannelSlack() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"is_private_channel": {
Type: schema.TypeBool,
Computed: true,
},
"private_channel_url": {
Type: schema.TypeString,
Computed: true,
},
"template_version": {
Type: schema.TypeString,
Computed: true,
Expand Down
2 changes: 2 additions & 0 deletions sysdig/internal/client/v2/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ type NotificationChannelOptions struct {
RoutingKey string `json:"routingKey,omitempty"` // Type: VictorOps
Url string `json:"url,omitempty"` // Type: OpsGenie, Webhook, Slack, google chat, prometheus alert manager, custom webhook, ms teams
Channel string `json:"channel,omitempty"` // Type: Slack
PrivateChannel bool `json:"privateChannel,omitempty"` // Type: Slack
PrivateChannelUrl string `json:"privateChannelUrl,omitempty"` // Type: Slack
Account string `json:"account,omitempty"` // Type: PagerDuty
ServiceKey string `json:"serviceKey,omitempty"` // Type: PagerDuty
ServiceName string `json:"serviceName,omitempty"` // Type: PagerDuty
Expand Down
15 changes: 15 additions & 0 deletions sysdig/resource_sysdig_monitor_notification_channel_slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ func resourceSysdigMonitorNotificationChannelSlack() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"is_private_channel": {
Type: schema.TypeBool,
Optional: true,
Default: false,
ForceNew: true,
},
"private_channel_url": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"show_section_runbook_links": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -193,6 +204,8 @@ func monitorNotificationChannelSlackFromResourceData(d *schema.ResourceData, tea
nc.Type = NOTIFICATION_CHANNEL_TYPE_SLACK
nc.Options.Url = d.Get("url").(string)
nc.Options.Channel = d.Get("channel").(string)
nc.Options.PrivateChannel = d.Get("is_private_channel").(bool)
nc.Options.PrivateChannelUrl = d.Get("private_channel_url").(string)
nc.Options.TemplateConfiguration = []v2.NotificationChannelTemplateConfiguration{
{
TemplateKey: "SLACK_MONITOR_ALERT_NOTIFICATION_TEMPLATE_METADATA_v1",
Expand Down Expand Up @@ -244,6 +257,8 @@ func monitorNotificationChannelSlackToResourceData(nc *v2.NotificationChannel, d

_ = d.Set("url", nc.Options.Url)
_ = d.Set("channel", nc.Options.Channel)
_ = d.Set("is_private_channel", nc.Options.PrivateChannel)
_ = d.Set("private_channel_url", nc.Options.PrivateChannelUrl)

runbookLinks := true
eventDetails := true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ func TestAccMonitorNotificationChannelSlack(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
{
Config: monitorNotificationChannelSlackSharedWithPrivateChannel(rText()),
},
{
ResourceName: "sysdig_monitor_notification_channel_slack.sample-slack-private",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -90,3 +98,15 @@ resource "sysdig_monitor_notification_channel_slack" "sample-slack" {
show_section_capturing_information = false
}`, name)
}

func monitorNotificationChannelSlackSharedWithPrivateChannel(name string) string {
return fmt.Sprintf(`
resource "sysdig_monitor_notification_channel_slack" "sample-slack-private" {
name = "Example Channel %s - Slack"
enabled = true
url = "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX"
channel = "#sysdig"
is_private_channel = true
private_channel_url = "https://app.slack.com/client/XXXXXXXX/XXXXXXXX"
}`, name)
}
15 changes: 15 additions & 0 deletions sysdig/resource_sysdig_secure_notification_channel_slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ func resourceSysdigSecureNotificationChannelSlack() *schema.Resource {
Type: schema.TypeString,
Required: true,
},
"is_private_channel": {
Type: schema.TypeBool,
Optional: true,
Default: false,
ForceNew: true,
},
"private_channel_url": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"template_version": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -163,6 +174,8 @@ func secureNotificationChannelSlackFromResourceData(d *schema.ResourceData, team
nc.Type = NOTIFICATION_CHANNEL_TYPE_SLACK
nc.Options.Url = d.Get("url").(string)
nc.Options.Channel = d.Get("channel").(string)
nc.Options.PrivateChannel = d.Get("is_private_channel").(bool)
nc.Options.PrivateChannelUrl = d.Get("private_channel_url").(string)

setNotificationChannelSlackTemplateConfig(&nc, d)

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

_ = d.Set("url", nc.Options.Url)
_ = d.Set("channel", nc.Options.Channel)
_ = d.Set("is_private_channel", nc.Options.PrivateChannel)
_ = d.Set("private_channel_url", nc.Options.PrivateChannelUrl)

err = getTemplateVersionFromNotificationChannelSlack(nc, d)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ func TestAccSecureNotificationChannelSlack(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
{
Config: secureNotificationChannelSlackSharedWithPrivateChannel(rText()),
},
{
ResourceName: "sysdig_secure_notification_channel_slack.sample-slack-private",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -89,3 +97,15 @@ resource "sysdig_secure_notification_channel_slack" "sample-slack" {
template_version = "%s"
}`, name, version)
}

func secureNotificationChannelSlackSharedWithPrivateChannel(name string) string {
return fmt.Sprintf(`
resource "sysdig_secure_notification_channel_slack" "sample-slack-private" {
name = "Example Channel %s - Slack"
enabled = true
url = "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX"
channel = "#sysdig"
is_private_channel = true
private_channel_url = "https://app.slack.com/client/XXXXXXXX/XXXXXXXX"
}`, name)
}
10 changes: 5 additions & 5 deletions website/docs/d/monitor_notification_channel_slack.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ data "sysdig_monitor_notification_channel_slack" "nc_slack" {
In addition to all arguments above, the following attributes are exported:

* `id` - The Notification Channel ID.
* `name` - The Notification Channel Name.
* `url` - URL of the Slack.
* `channel` - Channel name from this Slack.
* `url` - URL of the Slack webhook.
* `channel` - Name of the Slack channel.
* `is_private_channel` - Whether the Slack Channel has been marked as private or not.
* `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.
* `show_section_runbook_links` - Whether to include the runbook links section in the Slack messages.
* `show_section_event_details` - Whether to include the event details section in the Slack messages.
* `show_section_user_defined_content` - Whether to include the user defined section in the Slack messages.
Expand All @@ -41,7 +42,6 @@ In addition to all arguments above, the following attributes are exported:
* `show_section_capturing_information` - Whether to include the capturing information section in the Slack messages.
* `enabled` - Whether the Notification Channel is active or not.
* `notify_when_ok` - Whether the Notification Channel sends a notification when the condition is no longer triggered.
* `notify_when_resolved` - Whether the Notification Channel sends a notification if it's manually acknowledged by a
user.
* `notify_when_resolved` - Whether the Notification Channel sends a notification if it's manually acknowledged by a user.
* `version` - The version of the Notification Channel.
* `send_test_notification` - Whether the Notification Channel has enabled the test notification.
11 changes: 6 additions & 5 deletions website/docs/d/secure_notification_channel_slack.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ data "sysdig_secure_notification_channel_slack" "nc_slack" {
In addition to all arguments above, the following attributes are exported:

* `id` - The Notification Channel ID.
* `name` - The Notification Channel Name.
* `url` - URL of the Slack.
* `channel` - Channel name from this Slack.* `template_version` - The notification template version to use to create notifications.
* `url` - URL of the Slack webhook.
* `channel` - Name of the Slack channel.
* `is_private_channel` - Whether the Slack Channel has been marked as private or not.
* `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.
* `template_version` - The notification template version to use to create notifications.
* `enabled` - Whether the Notification Channel is active or not.
* `notify_when_ok` - Whether the Notification Channel sends a notification when the condition is no longer triggered.
* `notify_when_resolved` - Whether the Notification Channel sends a notification if it's manually acknowledged by a
user.
* `notify_when_resolved` - Whether the Notification Channel sends a notification if it's manually acknowledged by a user.
* `version` - The version of the Notification Channel.
* `send_test_notification` - Whether the Notification Channel has enabled the test notification.
9 changes: 7 additions & 2 deletions website/docs/r/monitor_notification_channel_slack.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ resource "sysdig_monitor_notification_channel_slack" "sample-slack" {
enabled = true
url = "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX"
channel = "#sysdig"
is_private_channel = false
notify_when_ok = false
notify_when_resolved = false
}
Expand All @@ -29,7 +30,7 @@ resource "sysdig_monitor_notification_channel_slack" "sample-slack" {

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

* `url` - (Required) URL of the Slack.
* `url` - (Required) URL of the Slack webhook.

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

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

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

* `channel` - (Required) Channel name from this Slack.
* `channel` - (Required) Name of the Slack channel. **NOTE**: If the channel is private this field cannot be changed after creation.

* `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.

* `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.

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

Expand Down
9 changes: 7 additions & 2 deletions website/docs/r/secure_notification_channel_slack.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ resource "sysdig_secure_notification_channel_slack" "sample-slack" {
enabled = true
url = "https://hooks.slack.com/services/XXXXXXXXX/XXXXXXXXX/XXXXXXXXXXXXXXXXXXXXXXXX"
channel = "#sysdig"
is_private_channel = false
notify_when_ok = false
notify_when_resolved = false
template_version = "v2"
Expand All @@ -30,9 +31,13 @@ resource "sysdig_secure_notification_channel_slack" "sample-slack" {

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

* `url` - (Required) URL of the Slack.
* `url` - (Required) URL of the Slack webhook.

* `channel` - (Required) Channel name from this Slack.
* `channel` - (Required) Name of the Slack channel. **NOTE**: If the channel is private this field cannot be changed after creation.

* `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.

* `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.

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

Expand Down
Loading