Skip to content
Open
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
8 changes: 4 additions & 4 deletions sysdig/internal/client/v2/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ type NotificationChannelOptions struct {
CustomData map[string]any `json:"customData,omitempty"` // Type: ibm function, Webhook
TemplateConfiguration []NotificationChannelTemplateConfiguration `json:"templateConfiguration,omitempty"` // Type: slack, ms teams

NotifyOnOk bool `json:"notifyOnOk"`
NotifyOnResolve bool `json:"notifyOnResolve"`
SendTestNotification bool `json:"sendTestNotification"`
NotifyOnOk *bool `json:"notifyOnOk,omitempty"`
NotifyOnResolve *bool `json:"notifyOnResolve,omitempty"`
SendTestNotification bool `json:"sendTestNotification"`
}

type NotificationChannel struct {
Expand Down Expand Up @@ -628,7 +628,7 @@ type NotificationChannelConfigV2 struct {
}

type NotificationChannelOptionsV2 struct {
NotifyOnAcknowledge bool `json:"notifyOnAcknowledge,omitempty"`
NotifyOnAcknowledge *bool `json:"notifyOnAcknowledge,omitempty"`
NotifyOnResolve bool `json:"notifyOnResolve"`
ReNotifyEverySec *int `json:"reNotifyEverySec"`
CustomNotificationTemplate *CustomNotificationTemplateV2 `json:"customNotificationTemplate,omitempty"`
Expand Down
23 changes: 23 additions & 0 deletions sysdig/resource_sysdig_monitor_alert_v2_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ func createAlertV2Schema(original map[string]*schema.Schema) map[string]*schema.
Optional: true,
Default: true,
},
"notify_on_acknowledge": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"true", "false"}, false),
},
"main_threshold": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -262,6 +267,16 @@ func buildAlertV2CommonStruct(d *schema.ResourceData) *v2.AlertV2Common {
}

newChannel.OverrideOptions.NotifyOnResolve = channelMap["notify_on_resolve"].(bool)
if notifyOnAcknowledge, ok := channelMap["notify_on_acknowledge"]; ok && notifyOnAcknowledge.(string) != "" {
if notifyOnAcknowledge.(string) == "true" {
trueValue := true
newChannel.OverrideOptions.NotifyOnAcknowledge = &trueValue
} else {
falseValue := false
newChannel.OverrideOptions.NotifyOnAcknowledge = &falseValue
}
// else do not set any value for newChannel.OverrideOptions.NotifyOnAcknowledge
}

newChannel.OverrideOptions.Thresholds = []string{}
mainThreshold := channelMap["main_threshold"].(bool)
Expand Down Expand Up @@ -358,6 +373,14 @@ func updateAlertV2CommonState(d *schema.ResourceData, alert *v2.AlertV2Common) (
"notify_on_resolve": ncc.OverrideOptions.NotifyOnResolve,
}

if ncc.OverrideOptions.NotifyOnAcknowledge != nil {
if *ncc.OverrideOptions.NotifyOnAcknowledge {
config["notify_on_acknowledge"] = "true"
} else {
config["notify_on_acknowledge"] = "false"
}
}

if ncc.OverrideOptions.ReNotifyEverySec != nil {
config["renotify_every_minutes"] = secondsToMinutes(*ncc.OverrideOptions.ReNotifyEverySec)
} else {
Expand Down
60 changes: 50 additions & 10 deletions sysdig/resource_sysdig_monitor_notification_channel_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sysdig
import (
v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

func createMonitorNotificationChannelSchema(original map[string]*schema.Schema) map[string]*schema.Schema {
Expand All @@ -22,14 +23,16 @@ func createMonitorNotificationChannelSchema(original map[string]*schema.Schema)
Default: false,
},
"notify_when_ok": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"true", "false"}, false),
Deprecated: "The notify_when_ok field is deprecated and will be removed in a future version. This flag has been replaced by the `notify_on_resolve` field inside `notification_channels` when defining an alert resource.",
},
"notify_when_resolved": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"true", "false"}, false),
Deprecated: "The notify_when_resolved field is deprecated and will be removed in a future version. This flag has been replaced by the `notify_on_acknowledge` field inside `notification_channels` when defining an alert resource.",
},
"version": {
Type: schema.TypeInt,
Expand All @@ -56,13 +59,35 @@ func monitorNotificationChannelFromResourceData(d *schema.ResourceData, teamID i
tID = &teamID
}

var notifyOnOk *bool = nil
if onOk, ok := d.GetOk("notify_when_ok"); ok && onOk.(string) != "" {
if onOk.(string) == "true" {
trueValue := true
notifyOnOk = &trueValue
} else {
falseValue := false
notifyOnOk = &falseValue
}
}

var notifyOnResolve *bool = nil
if onResolve, ok := d.GetOk("notify_when_resolved"); ok && onResolve.(string) != "" {
if onResolve.(string) == "true" {
trueValue := true
notifyOnResolve = &trueValue
} else {
falseValue := false
notifyOnResolve = &falseValue
}
}

nc = v2.NotificationChannel{
Name: d.Get("name").(string),
Enabled: d.Get("enabled").(bool),
TeamID: tID,
Options: v2.NotificationChannelOptions{
NotifyOnOk: d.Get("notify_when_ok").(bool),
NotifyOnResolve: d.Get("notify_when_resolved").(bool),
NotifyOnOk: notifyOnOk,
NotifyOnResolve: notifyOnResolve,
SendTestNotification: d.Get("send_test_notification").(bool),
},
}
Expand All @@ -82,8 +107,23 @@ func monitorNotificationChannelToResourceData(nc *v2.NotificationChannel, data *
if err != nil {
return err
}
_ = data.Set("notify_when_ok", nc.Options.NotifyOnOk)
_ = data.Set("notify_when_resolved", nc.Options.NotifyOnResolve)

if nc.Options.NotifyOnOk != nil {
if *nc.Options.NotifyOnOk {
_ = data.Set("notify_when_ok", "true")
} else {
_ = data.Set("notify_when_ok", "false")
}
}

if nc.Options.NotifyOnResolve != nil {
if *nc.Options.NotifyOnResolve {
_ = data.Set("notify_when_resolved", "true")
} else {
_ = data.Set("notify_when_resolved", "false")
}
}

// do not update "send_test_notification" from the api response as it will always be "false" on subsequent reads because the fields is not persisted

return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ func TestAccMonitorNotificationChannelCustomWebhook(t *testing.T) {
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"send_test_notification"},
},
{
Config: monitorNotificationChannelCustomWebhookWithoutNotifyFields(rText()),
},
{
ResourceName: "sysdig_monitor_notification_channel_custom_webhook.sample-custom-webhook6",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"send_test_notification"},
},
},
})
}
Expand Down Expand Up @@ -150,3 +159,15 @@ func monitorNotificationChannelCustomWebhookSharedWithAdditionalHeaders(name str
send_test_notification = false
}`, name)
}

func monitorNotificationChannelCustomWebhookWithoutNotifyFields(name string) string {
return fmt.Sprintf(`
resource "sysdig_monitor_notification_channel_custom_webhook" "sample-custom-webhook6" {
name = "Example Channel %s - Custom Webhook"
enabled = true
url = "https://example.com/"
http_method = "POST"
template = "{\n \"code\": \"incident\",\n \"alert\": \"{{@alert_name}}\"\n}"
send_test_notification = false
}`, name)
}
60 changes: 50 additions & 10 deletions sysdig/resource_sysdig_secure_notification_channel_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sysdig
import (
v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

func createSecureNotificationChannelSchema(original map[string]*schema.Schema) map[string]*schema.Schema {
Expand All @@ -22,14 +23,16 @@ func createSecureNotificationChannelSchema(original map[string]*schema.Schema) m
Default: false,
},
"notify_when_ok": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"true", "false"}, false),
Deprecated: "The notify_when_ok field is deprecated and will be removed in a future version. This flag has been replaced by the `notify_on_resolve` field inside `notification_channels` when defining an alert resource.",
},
"notify_when_resolved": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"true", "false"}, false),
Deprecated: "The notify_when_resolved field is deprecated and will be removed in a future version. This flag has been replaced by the `notify_on_acknowledge` field inside `notification_channels` when defining an alert resource.",
},
"version": {
Type: schema.TypeInt,
Expand All @@ -56,13 +59,35 @@ func secureNotificationChannelFromResourceData(d *schema.ResourceData, teamID in
tID = &teamID
}

var notifyOnOk *bool = nil
if onOk, ok := d.GetOk("notify_when_ok"); ok && onOk.(string) != "" {
if onOk.(string) == "true" {
trueValue := true
notifyOnOk = &trueValue
} else {
falseValue := false
notifyOnOk = &falseValue
}
}

var notifyOnResolve *bool = nil
if onResolve, ok := d.GetOk("notify_when_resolved"); ok && onResolve.(string) != "" {
if onResolve.(string) == "true" {
trueValue := true
notifyOnResolve = &trueValue
} else {
falseValue := false
notifyOnResolve = &falseValue
}
}

nc = v2.NotificationChannel{
Name: d.Get("name").(string),
Enabled: d.Get("enabled").(bool),
TeamID: tID,
Options: v2.NotificationChannelOptions{
NotifyOnOk: d.Get("notify_when_ok").(bool),
NotifyOnResolve: d.Get("notify_when_resolved").(bool),
NotifyOnOk: notifyOnOk,
NotifyOnResolve: notifyOnResolve,
SendTestNotification: d.Get("send_test_notification").(bool),
},
}
Expand All @@ -82,8 +107,23 @@ func secureNotificationChannelToResourceData(nc *v2.NotificationChannel, data *s
if err != nil {
return err
}
_ = data.Set("notify_when_ok", nc.Options.NotifyOnOk)
_ = data.Set("notify_when_resolved", nc.Options.NotifyOnResolve)

if nc.Options.NotifyOnOk != nil {
if *nc.Options.NotifyOnOk {
_ = data.Set("notify_when_ok", "true")
} else {
_ = data.Set("notify_when_ok", "false")
}
}

if nc.Options.NotifyOnResolve != nil {
if *nc.Options.NotifyOnResolve {
_ = data.Set("notify_when_resolved", "true")
} else {
_ = data.Set("notify_when_resolved", "false")
}
}

// do not update "send_test_notification" from the api response as it will always be "false" on subsequent reads because the fields is not persisted

return err
Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/monitor_alert_v2_change.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ By defining this field, the user can choose to which notification channels send
It is a list of objects with the following fields:
* `id` - (Required) The ID of the notification channel.
* `renotify_every_minutes` - (Optional) the amount of minutes to wait before re sending the notification to this channel. `0` means no renotification enabled. Default: `0`.
* `notify_on_resolve` - (Optional) Wether to send a notification when the alert is resolved. Default: `true`.
* `notify_on_resolve` - (Optional) Whether to send a notification when the alert is resolved. Default: `true`.
* `notify_on_acknowledge` - (Optional) Whether to send a notification when the alert is acknowledged. If not defined, this option is inherited from the `notify_when_resolved` option from the specific notification channel selected. If it is not defined there, the default is to send notification on acknowledgement.
* `main_threshold` - (Optional) Whether this notification channel is used for the main threshold of the alert. Default: `true`.
* `warning_threshold` - (Optional) Whether this notification channel is used for the warning threshold of the alert. Default: `false`.

Expand Down
5 changes: 3 additions & 2 deletions website/docs/r/monitor_alert_v2_downtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ By defining this field, the user can choose to which notification channels send
It is a list of objects with the following fields:
* `id` - (Required) The ID of the notification channel.
* `renotify_every_minutes` - (Optional) the amount of minutes to wait before re sending the notification to this channel. `0` means no renotification enabled. Default: `0`.
* `notify_on_resolve` - (Optional) Wether to send a notification when the alert is resolved. Default: `true`.
* `notify_on_resolve` - (Optional) Whether to send a notification when the alert is resolved. Default: `true`.
* `notify_on_acknowledge` - (Optional) Whether to send a notification when the alert is acknowledged. If not defined, this option is inherited from the `notify_when_resolved` option from the specific notification channel selected. If it is not defined there, the default is to send notification on acknowledgement.

### `custom_notification`

Expand Down Expand Up @@ -94,7 +95,7 @@ Enables the creation of a capture file of the syscalls during the event.
* `duration_seconds` - (Optional) Time frame of the capture. Default: `15`.
* `storage` - (Optional) Custom bucket where to save the capture.
* `filter` - (Optional) Additional filter to apply to the capture. For example: `proc.name contains nginx`.
* `enabled` - (Optional) Wether to enable captures. Default: `true`.
* `enabled` - (Optional) Whether to enable captures. Default: `true`.

### Downtime alert arguments

Expand Down
5 changes: 3 additions & 2 deletions website/docs/r/monitor_alert_v2_event.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ By defining this field, the user can choose to which notification channels send
It is a list of objects with the following fields:
* `id` - (Required) The ID of the notification channel.
* `renotify_every_minutes` - (Optional) the amount of minutes to wait before re sending the notification to this channel. `0` means no renotification enabled. Default: `0`.
* `notify_on_resolve` - (Optional) Wether to send a notification when the alert is resolved. Default: `true`.
* `notify_on_resolve` - (Optional) Whether to send a notification when the alert is resolved. Default: `true`.
* `notify_on_acknowledge` - (Optional) Whether to send a notification when the alert is acknowledged. If not defined, this option is inherited from the `notify_when_resolved` option from the specific notification channel selected. If it is not defined there, the default is to send notification on acknowledgement.
* `main_threshold` - (Optional) Whether this notification channel is used for the main threshold of the alert. Default: `true`.
* `warning_threshold` - (Optional) Whether this notification channel is used for the warning threshold of the alert. Default: `false`.

Expand Down Expand Up @@ -106,7 +107,7 @@ Enables the creation of a capture file of the syscalls during the event.
* `duration_seconds` - (Optional) Time frame of the capture. Default: `15`.
* `storage` - (Optional) Custom bucket where to save the capture.
* `filter` - (Optional) Additional filter to apply to the capture. For example: `proc.name contains nginx`.
* `enabled` - (Optional) Wether to enable captures. Default: `true`.
* `enabled` - (Optional) Whether to enable captures. Default: `true`.

### Event alert arguments

Expand Down
3 changes: 2 additions & 1 deletion website/docs/r/monitor_alert_v2_form_based_prometheus.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ By defining this field, the user can choose to which notification channels send
It is a list of objects with the following fields:
* `id` - (Required) The ID of the notification channel.
* `renotify_every_minutes` - (Optional) the amount of minutes to wait before re sending the notification to this channel. `0` means no renotification enabled.
* `notify_on_resolve` - (Optional) Wether to send a notification when the alert is resolved. Default: `true`.
* `notify_on_resolve` - (Optional) Whether to send a notification when the alert is resolved. Default: `true`.
* `notify_on_acknowledge` - (Optional) Whether to send a notification when the alert is acknowledged. If not defined, this option is inherited from the `notify_when_resolved` option from the specific notification channel selected. If it is not defined there, the default is to send notification on acknowledgement.
* `main_threshold` - (Optional) Whether this notification channel is used for the main threshold of the alert. Default: `true`.
* `warning_threshold` - (Optional) Whether this notification channel is used for the warning threshold of the alert. Default: `false`.

Expand Down
5 changes: 3 additions & 2 deletions website/docs/r/monitor_alert_v2_group_outlier.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ By defining this field, the user can choose to which notification channels send
It is a list of objects with the following fields:
* `id` - (Required) The ID of the notification channel.
* `renotify_every_minutes` - (Optional) the amount of minutes to wait before re sending the notification to this channel. `0` means no renotification enabled. Default: `0`.
* `notify_on_resolve` - (Optional) Wether to send a notification when the alert is resolved. Default: `true`.
* `notify_on_resolve` - (Optional) Whether to send a notification when the alert is resolved. Default: `true`.
* `notify_on_acknowledge` - (Optional) Whether to send a notification when the alert is acknowledged. If not defined, this option is inherited from the `notify_when_resolved` option from the specific notification channel selected. If it is not defined there, the default is to send notification on acknowledgement.
* `main_threshold` - (Optional) Whether this notification channel is used for the main threshold of the alert. Default: `true`.
* `warning_threshold` - (Optional) Whether this notification channel is used for the warning threshold of the alert. Default: `false`.

Expand Down Expand Up @@ -108,7 +109,7 @@ Enables the creation of a capture file of the syscalls during the event.
* `duration_seconds` - (Optional) Time frame of the capture. Default: `15`.
* `storage` - (Optional) Custom bucket where to save the capture.
* `filter` - (Optional) Additional filter to apply to the capture. For example: `proc.name contains nginx`.
* `enabled` - (Optional) Wether to enable captures. Default: `true`.
* `enabled` - (Optional) Whether to enable captures. Default: `true`.

### Group Outlier alert arguments

Expand Down
5 changes: 3 additions & 2 deletions website/docs/r/monitor_alert_v2_metric.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ By defining this field, the user can choose to which notification channels send
It is a list of objects with the following fields:
* `id` - (Required) The ID of the notification channel.
* `renotify_every_minutes` - (Optional) the amount of minutes to wait before re sending the notification to this channel. `0` means no renotification enabled. Default: `0`.
* `notify_on_resolve` - (Optional) Wether to send a notification when the alert is resolved. Default: `true`.
* `notify_on_resolve` - (Optional) Whether to send a notification when the alert is resolved. Default: `true`.
* `notify_on_acknowledge` - (Optional) Whether to send a notification when the alert is acknowledged. If not defined, this option is inherited from the `notify_when_resolved` option from the specific notification channel selected. If it is not defined there, the default is to send notification on acknowledgement.
* `main_threshold` - (Optional) Whether this notification channel is used for the main threshold of the alert. Default: `true`.
* `warning_threshold` - (Optional) Whether this notification channel is used for the warning threshold of the alert. Default: `false`.

Expand Down Expand Up @@ -123,7 +124,7 @@ Enables the creation of a capture file of the syscalls during the event.
* `duration_seconds` - (Optional) Time frame of the capture. Default: `15`.
* `storage` - (Optional) Custom bucket where to save the capture.
* `filter` - (Optional) Additional filter to apply to the capture. For example: `proc.name contains nginx`.
* `enabled` - (Optional) Wether to enable captures. Default: `true`.
* `enabled` - (Optional) Whether to enable captures. Default: `true`.

### Metric Threshold alert arguments

Expand Down
Loading
Loading