Skip to content

Commit 48d49ac

Browse files
committed
feat(slack notification channel) support slack private channel
1 parent fa950b7 commit 48d49ac

11 files changed

+85
-38
lines changed

sysdig/data_source_sysdig_monitor_notification_channel_slack.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ func dataSourceSysdigMonitorNotificationChannelSlack() *schema.Resource {
2929
Type: schema.TypeString,
3030
Computed: true,
3131
},
32-
"is_private_channel": {
32+
"private_channel": {
3333
Type: schema.TypeBool,
34-
Required: false,
34+
Computed: true,
3535
},
3636
"private_channel_url": {
3737
Type: schema.TypeString,
38-
Required: false,
38+
Computed: true,
3939
},
4040
"show_section_runbook_links": {
4141
Type: schema.TypeBool,

sysdig/data_source_sysdig_secure_notification_channel_slack.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ func dataSourceSysdigSecureNotificationChannelSlack() *schema.Resource {
2929
Type: schema.TypeString,
3030
Computed: true,
3131
},
32-
"is_private_channel": {
32+
"private_channel": {
3333
Type: schema.TypeBool,
34-
Required: false,
34+
Computed: true,
3535
},
3636
"private_channel_url": {
3737
Type: schema.TypeString,
38-
Required: false,
38+
Computed: true,
3939
},
4040
"template_version": {
4141
Type: schema.TypeString,

sysdig/internal/client/v2/model.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +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-
IsPrivateChannel *bool `json:"isPrivateChannel,omitEmpty"` // Type: Slack
125-
PrivateChannelUrl string `json:"privateChannelUrl,omitEmpty"` // Type: Slack (if channel is private)
124+
PrivateChannel bool `json:"privateChannel,omitempty"` // Type: Slack
125+
PrivateChannelUrl string `json:"privateChannelUrl,omitempty"` // Type: Slack
126126
Account string `json:"account,omitempty"` // Type: PagerDuty
127127
ServiceKey string `json:"serviceKey,omitempty"` // Type: PagerDuty
128128
ServiceName string `json:"serviceName,omitempty"` // Type: PagerDuty

sysdig/resource_sysdig_monitor_notification_channel_slack.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@ func resourceSysdigMonitorNotificationChannelSlack() *schema.Resource {
4040
Type: schema.TypeString,
4141
Required: true,
4242
},
43-
"is_private_channel": {
43+
"private_channel": {
4444
Type: schema.TypeBool,
45-
Required: false,
45+
Optional: true,
46+
Default: false,
47+
ForceNew: true,
4648
},
4749
"private_channel_url": {
4850
Type: schema.TypeString,
49-
Required: false,
51+
Optional: true,
52+
ForceNew: true,
5053
},
5154
"show_section_runbook_links": {
5255
Type: schema.TypeBool,
@@ -201,7 +204,7 @@ func monitorNotificationChannelSlackFromResourceData(d *schema.ResourceData, tea
201204
nc.Type = NOTIFICATION_CHANNEL_TYPE_SLACK
202205
nc.Options.Url = d.Get("url").(string)
203206
nc.Options.Channel = d.Get("channel").(string)
204-
nc.Options.IsPrivateChannel = d.Get("is_private_channel").(bool)
207+
nc.Options.PrivateChannel = d.Get("private_channel").(bool)
205208
nc.Options.PrivateChannelUrl = d.Get("private_channel_url").(string)
206209
nc.Options.TemplateConfiguration = []v2.NotificationChannelTemplateConfiguration{
207210
{
@@ -254,7 +257,7 @@ func monitorNotificationChannelSlackToResourceData(nc *v2.NotificationChannel, d
254257

255258
_ = d.Set("url", nc.Options.Url)
256259
_ = d.Set("channel", nc.Options.Channel)
257-
_ = d.Set("is_private_channel", nc.Options.IsPrivateChannel)
260+
_ = d.Set("private_channel", nc.Options.PrivateChannel)
258261
_ = d.Set("private_channel_url", nc.Options.PrivateChannelUrl)
259262

260263
runbookLinks := true

sysdig/resource_sysdig_monitor_notification_channel_slack_test.go

Lines changed: 20 additions & 0 deletions
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 monitorNotificationChannelSlackSharedWithShowSection(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+
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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@ func resourceSysdigSecureNotificationChannelSlack() *schema.Resource {
4141
Type: schema.TypeString,
4242
Required: true,
4343
},
44-
"is_private_channel": {
44+
"private_channel": {
4545
Type: schema.TypeBool,
46-
Required: false,
46+
Optional: true,
47+
Default: false,
48+
ForceNew: true,
4749
},
4850
"private_channel_url": {
4951
Type: schema.TypeString,
50-
Required: false,
52+
Optional: true,
53+
ForceNew: true,
5154
},
5255
"template_version": {
5356
Type: schema.TypeString,
@@ -171,7 +174,7 @@ func secureNotificationChannelSlackFromResourceData(d *schema.ResourceData, team
171174
nc.Type = NOTIFICATION_CHANNEL_TYPE_SLACK
172175
nc.Options.Url = d.Get("url").(string)
173176
nc.Options.Channel = d.Get("channel").(string)
174-
nc.Options.IsPrivateChannel = d.Get("is_private_channel").(bool)
177+
nc.Options.PrivateChannel = d.Get("private_channel").(bool)
175178
nc.Options.PrivateChannelUrl = d.Get("private_channel_url").(string)
176179

177180
setNotificationChannelSlackTemplateConfig(&nc, d)
@@ -218,7 +221,7 @@ func secureNotificationChannelSlackToResourceData(nc *v2.NotificationChannel, d
218221

219222
_ = d.Set("url", nc.Options.Url)
220223
_ = d.Set("channel", nc.Options.Channel)
221-
_ = d.Set("is_private_channel", nc.Options.IsPrivateChannel)
224+
_ = d.Set("private_channel", nc.Options.PrivateChannel)
222225
_ = d.Set("private_channel_url", nc.Options.PrivateChannelUrl)
223226

224227
err = getTemplateVersionFromNotificationChannelSlack(nc, d)

sysdig/resource_sysdig_secure_notification_channel_slack_test.go

Lines changed: 20 additions & 0 deletions
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 secureNotificationChannelSlackWithName(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+
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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +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.
35-
* `is_private_channel` - Whether the Slack channel is private or not.
36-
* `private_channel_url` - The channel URL,
32+
* `url` - URL of the Slack webhook.
33+
* `channel` - Name of the Slack channel.
34+
* `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.
3736
* `show_section_runbook_links` - Whether to include the runbook links section in the Slack messages.
3837
* `show_section_event_details` - Whether to include the event details section in the Slack messages.
3938
* `show_section_user_defined_content` - Whether to include the user defined section in the Slack messages.
@@ -43,7 +42,6 @@ In addition to all arguments above, the following attributes are exported:
4342
* `show_section_capturing_information` - Whether to include the capturing information section in the Slack messages.
4443
* `enabled` - Whether the Notification Channel is active or not.
4544
* `notify_when_ok` - Whether the Notification Channel sends a notification when the condition is no longer triggered.
46-
* `notify_when_resolved` - Whether the Notification Channel sends a notification if it's manually acknowledged by a
47-
user.
45+
* `notify_when_resolved` - Whether the Notification Channel sends a notification if it's manually acknowledged by a user.
4846
* `version` - The version of the Notification Channel.
4947
* `send_test_notification` - Whether the Notification Channel has enabled the test notification.

website/docs/d/secure_notification_channel_slack.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +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.
35-
* `is_private_channel` - Whether the Slack channel is private or not.
36-
* `private_channel_url` - The channel URL,
32+
* `url` - URL of the Slack webhook.
33+
* `channel` - Name of the Slack channel.
34+
* `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.
3737
* `enabled` - Whether the Notification Channel is active or not.
3838
* `notify_when_ok` - Whether the Notification Channel sends a notification when the condition is no longer triggered.
39-
* `notify_when_resolved` - Whether the Notification Channel sends a notification if it's manually acknowledged by a
40-
user.
39+
* `notify_when_resolved` - Whether the Notification Channel sends a notification if it's manually acknowledged by a user.
4140
* `version` - The version of the Notification Channel.
4241
* `send_test_notification` - Whether the Notification Channel has enabled the test notification.

website/docs/r/monitor_notification_channel_slack.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ resource "sysdig_monitor_notification_channel_slack" "sample-slack" {
3030

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

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

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

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

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

49-
* `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+
* `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.
5054

5155
* `is_private_channel` - (Optional) Whether the Slack channel is private or not.
5256

website/docs/r/secure_notification_channel_slack.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ resource "sysdig_secure_notification_channel_slack" "sample-slack" {
3131

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

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

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

38-
* `is_private_channel` - (Optional) Whether the Slack channel is private or not.
38+
* `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.
3939

40-
* `private_channel_url` - (Optional) The channel URL, if channel is private.
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.
4141

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

0 commit comments

Comments
 (0)