diff --git a/sysdig/data_source_sysdig_monitor_notification_channel_slack.go b/sysdig/data_source_sysdig_monitor_notification_channel_slack.go index 748c01f0..321d7176 100644 --- a/sysdig/data_source_sysdig_monitor_notification_channel_slack.go +++ b/sysdig/data_source_sysdig_monitor_notification_channel_slack.go @@ -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, diff --git a/sysdig/data_source_sysdig_secure_notification_channel_slack.go b/sysdig/data_source_sysdig_secure_notification_channel_slack.go index d09f8ed4..48694398 100644 --- a/sysdig/data_source_sysdig_secure_notification_channel_slack.go +++ b/sysdig/data_source_sysdig_secure_notification_channel_slack.go @@ -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, diff --git a/sysdig/internal/client/v2/model.go b/sysdig/internal/client/v2/model.go index 1f8f8cb8..e5fb9973 100644 --- a/sysdig/internal/client/v2/model.go +++ b/sysdig/internal/client/v2/model.go @@ -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 diff --git a/sysdig/resource_sysdig_monitor_notification_channel_slack.go b/sysdig/resource_sysdig_monitor_notification_channel_slack.go index 21723eb1..0b2fbb9c 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_slack.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_slack.go @@ -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, @@ -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", @@ -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 diff --git a/sysdig/resource_sysdig_monitor_notification_channel_slack_test.go b/sysdig/resource_sysdig_monitor_notification_channel_slack_test.go index 527f2120..75b1b014 100644 --- a/sysdig/resource_sysdig_monitor_notification_channel_slack_test.go +++ b/sysdig/resource_sysdig_monitor_notification_channel_slack_test.go @@ -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, + }, }, }) } @@ -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) +} diff --git a/sysdig/resource_sysdig_secure_notification_channel_slack.go b/sysdig/resource_sysdig_secure_notification_channel_slack.go index 93132213..23b8cb6b 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_slack.go +++ b/sysdig/resource_sysdig_secure_notification_channel_slack.go @@ -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, @@ -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) @@ -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) diff --git a/sysdig/resource_sysdig_secure_notification_channel_slack_test.go b/sysdig/resource_sysdig_secure_notification_channel_slack_test.go index 8e52979f..d4044c46 100644 --- a/sysdig/resource_sysdig_secure_notification_channel_slack_test.go +++ b/sysdig/resource_sysdig_secure_notification_channel_slack_test.go @@ -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, + }, }, }) } @@ -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) +} diff --git a/website/docs/d/monitor_notification_channel_slack.md b/website/docs/d/monitor_notification_channel_slack.md index 69ca404a..9fb7f311 100644 --- a/website/docs/d/monitor_notification_channel_slack.md +++ b/website/docs/d/monitor_notification_channel_slack.md @@ -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. @@ -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. diff --git a/website/docs/d/secure_notification_channel_slack.md b/website/docs/d/secure_notification_channel_slack.md index 86d2d4d8..1885f46a 100644 --- a/website/docs/d/secure_notification_channel_slack.md +++ b/website/docs/d/secure_notification_channel_slack.md @@ -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. diff --git a/website/docs/r/monitor_notification_channel_slack.md b/website/docs/r/monitor_notification_channel_slack.md index 95c279fd..0c569eb9 100644 --- a/website/docs/r/monitor_notification_channel_slack.md +++ b/website/docs/r/monitor_notification_channel_slack.md @@ -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 } @@ -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. @@ -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. diff --git a/website/docs/r/secure_notification_channel_slack.md b/website/docs/r/secure_notification_channel_slack.md index ae81b477..ee726ee5 100644 --- a/website/docs/r/secure_notification_channel_slack.md +++ b/website/docs/r/secure_notification_channel_slack.md @@ -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" @@ -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.