Skip to content

Commit d5cea38

Browse files
committed
avoid removing defaults for notify_when_ok and notify_when_resolved
1 parent b440c61 commit d5cea38

34 files changed

Lines changed: 80 additions & 177 deletions

sysdig/internal/client/v2/model.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ type NotificationChannelOptions struct {
138138
CustomData map[string]any `json:"customData,omitempty"` // Type: ibm function, Webhook
139139
TemplateConfiguration []NotificationChannelTemplateConfiguration `json:"templateConfiguration,omitempty"` // Type: slack, ms teams
140140

141-
NotifyOnOk *bool `json:"notifyOnOk,omitempty"`
142-
NotifyOnResolve *bool `json:"notifyOnResolve,omitempty"`
143-
SendTestNotification bool `json:"sendTestNotification"`
141+
NotifyOnOk bool `json:"notifyOnOk"`
142+
NotifyOnResolve bool `json:"notifyOnResolve"`
143+
SendTestNotification bool `json:"sendTestNotification"`
144144
}
145145

146146
type NotificationChannel struct {

sysdig/resource_sysdig_monitor_notification_channel_common.go

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package sysdig
33
import (
44
v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2"
55
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
6-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
76
)
87

98
func createMonitorNotificationChannelSchema(original map[string]*schema.Schema) map[string]*schema.Schema {
@@ -23,16 +22,16 @@ func createMonitorNotificationChannelSchema(original map[string]*schema.Schema)
2322
Default: false,
2423
},
2524
"notify_when_ok": {
26-
Type: schema.TypeString,
27-
Optional: true,
28-
ValidateFunc: validation.StringInSlice([]string{"true", "false"}, false),
29-
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.",
25+
Type: schema.TypeBool,
26+
Optional: true,
27+
Default: false,
28+
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.",
3029
},
3130
"notify_when_resolved": {
32-
Type: schema.TypeString,
33-
Optional: true,
34-
ValidateFunc: validation.StringInSlice([]string{"true", "false"}, false),
35-
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.",
31+
Type: schema.TypeBool,
32+
Optional: true,
33+
Default: false,
34+
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.",
3635
},
3736
"version": {
3837
Type: schema.TypeInt,
@@ -59,35 +58,13 @@ func monitorNotificationChannelFromResourceData(d *schema.ResourceData, teamID i
5958
tID = &teamID
6059
}
6160

62-
var notifyOnOk *bool = nil
63-
if onOk, ok := d.GetOk("notify_when_ok"); ok && onOk.(string) != "" {
64-
if onOk.(string) == "true" {
65-
trueValue := true
66-
notifyOnOk = &trueValue
67-
} else {
68-
falseValue := false
69-
notifyOnOk = &falseValue
70-
}
71-
}
72-
73-
var notifyOnResolve *bool = nil
74-
if onResolve, ok := d.GetOk("notify_when_resolved"); ok && onResolve.(string) != "" {
75-
if onResolve.(string) == "true" {
76-
trueValue := true
77-
notifyOnResolve = &trueValue
78-
} else {
79-
falseValue := false
80-
notifyOnResolve = &falseValue
81-
}
82-
}
83-
8461
nc = v2.NotificationChannel{
8562
Name: d.Get("name").(string),
8663
Enabled: d.Get("enabled").(bool),
8764
TeamID: tID,
8865
Options: v2.NotificationChannelOptions{
89-
NotifyOnOk: notifyOnOk,
90-
NotifyOnResolve: notifyOnResolve,
66+
NotifyOnOk: d.Get("notify_when_ok").(bool),
67+
NotifyOnResolve: d.Get("notify_when_resolved").(bool),
9168
SendTestNotification: d.Get("send_test_notification").(bool),
9269
},
9370
}
@@ -107,23 +84,8 @@ func monitorNotificationChannelToResourceData(nc *v2.NotificationChannel, data *
10784
if err != nil {
10885
return err
10986
}
110-
111-
if nc.Options.NotifyOnOk != nil {
112-
if *nc.Options.NotifyOnOk {
113-
_ = data.Set("notify_when_ok", "true")
114-
} else {
115-
_ = data.Set("notify_when_ok", "false")
116-
}
117-
}
118-
119-
if nc.Options.NotifyOnResolve != nil {
120-
if *nc.Options.NotifyOnResolve {
121-
_ = data.Set("notify_when_resolved", "true")
122-
} else {
123-
_ = data.Set("notify_when_resolved", "false")
124-
}
125-
}
126-
87+
_ = data.Set("notify_when_ok", nc.Options.NotifyOnOk)
88+
_ = data.Set("notify_when_resolved", nc.Options.NotifyOnResolve)
12789
// 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
12890

12991
return err

sysdig/resource_sysdig_monitor_notification_channel_custom_webhook_test.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,6 @@ func TestAccMonitorNotificationChannelCustomWebhook(t *testing.T) {
6969
ImportStateVerify: true,
7070
ImportStateVerifyIgnore: []string{"send_test_notification"},
7171
},
72-
{
73-
Config: monitorNotificationChannelCustomWebhookWithoutNotifyFields(rText()),
74-
},
75-
{
76-
ResourceName: "sysdig_monitor_notification_channel_custom_webhook.sample-custom-webhook6",
77-
ImportState: true,
78-
ImportStateVerify: true,
79-
ImportStateVerifyIgnore: []string{"send_test_notification"},
80-
},
8172
},
8273
})
8374
}
@@ -159,15 +150,3 @@ func monitorNotificationChannelCustomWebhookSharedWithAdditionalHeaders(name str
159150
send_test_notification = false
160151
}`, name)
161152
}
162-
163-
func monitorNotificationChannelCustomWebhookWithoutNotifyFields(name string) string {
164-
return fmt.Sprintf(`
165-
resource "sysdig_monitor_notification_channel_custom_webhook" "sample-custom-webhook6" {
166-
name = "Example Channel %s - Custom Webhook"
167-
enabled = true
168-
url = "https://example.com/"
169-
http_method = "POST"
170-
template = "{\n \"code\": \"incident\",\n \"alert\": \"{{@alert_name}}\"\n}"
171-
send_test_notification = false
172-
}`, name)
173-
}

sysdig/resource_sysdig_secure_notification_channel_common.go

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package sysdig
33
import (
44
v2 "github.com/draios/terraform-provider-sysdig/sysdig/internal/client/v2"
55
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
6-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
76
)
87

98
func createSecureNotificationChannelSchema(original map[string]*schema.Schema) map[string]*schema.Schema {
@@ -23,16 +22,16 @@ func createSecureNotificationChannelSchema(original map[string]*schema.Schema) m
2322
Default: false,
2423
},
2524
"notify_when_ok": {
26-
Type: schema.TypeString,
27-
Optional: true,
28-
ValidateFunc: validation.StringInSlice([]string{"true", "false"}, false),
29-
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.",
25+
Type: schema.TypeBool,
26+
Optional: true,
27+
Default: false,
28+
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.",
3029
},
3130
"notify_when_resolved": {
32-
Type: schema.TypeString,
33-
Optional: true,
34-
ValidateFunc: validation.StringInSlice([]string{"true", "false"}, false),
35-
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.",
31+
Type: schema.TypeBool,
32+
Optional: true,
33+
Default: false,
34+
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.",
3635
},
3736
"version": {
3837
Type: schema.TypeInt,
@@ -59,35 +58,13 @@ func secureNotificationChannelFromResourceData(d *schema.ResourceData, teamID in
5958
tID = &teamID
6059
}
6160

62-
var notifyOnOk *bool = nil
63-
if onOk, ok := d.GetOk("notify_when_ok"); ok && onOk.(string) != "" {
64-
if onOk.(string) == "true" {
65-
trueValue := true
66-
notifyOnOk = &trueValue
67-
} else {
68-
falseValue := false
69-
notifyOnOk = &falseValue
70-
}
71-
}
72-
73-
var notifyOnResolve *bool = nil
74-
if onResolve, ok := d.GetOk("notify_when_resolved"); ok && onResolve.(string) != "" {
75-
if onResolve.(string) == "true" {
76-
trueValue := true
77-
notifyOnResolve = &trueValue
78-
} else {
79-
falseValue := false
80-
notifyOnResolve = &falseValue
81-
}
82-
}
83-
8461
nc = v2.NotificationChannel{
8562
Name: d.Get("name").(string),
8663
Enabled: d.Get("enabled").(bool),
8764
TeamID: tID,
8865
Options: v2.NotificationChannelOptions{
89-
NotifyOnOk: notifyOnOk,
90-
NotifyOnResolve: notifyOnResolve,
66+
NotifyOnOk: d.Get("notify_when_ok").(bool),
67+
NotifyOnResolve: d.Get("notify_when_resolved").(bool),
9168
SendTestNotification: d.Get("send_test_notification").(bool),
9269
},
9370
}
@@ -107,23 +84,8 @@ func secureNotificationChannelToResourceData(nc *v2.NotificationChannel, data *s
10784
if err != nil {
10885
return err
10986
}
110-
111-
if nc.Options.NotifyOnOk != nil {
112-
if *nc.Options.NotifyOnOk {
113-
_ = data.Set("notify_when_ok", "true")
114-
} else {
115-
_ = data.Set("notify_when_ok", "false")
116-
}
117-
}
118-
119-
if nc.Options.NotifyOnResolve != nil {
120-
if *nc.Options.NotifyOnResolve {
121-
_ = data.Set("notify_when_resolved", "true")
122-
} else {
123-
_ = data.Set("notify_when_resolved", "false")
124-
}
125-
}
126-
87+
_ = data.Set("notify_when_ok", nc.Options.NotifyOnOk)
88+
_ = data.Set("notify_when_resolved", nc.Options.NotifyOnResolve)
12789
// 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
12890

12991
return err

website/docs/r/monitor_alert_v2_change.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ It is a list of objects with the following fields:
7676
* `id` - (Required) The ID of the notification channel.
7777
* `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`.
7878
* `notify_on_resolve` - (Optional) Whether to send a notification when the alert is resolved. Default: `true`.
79-
* `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.
79+
* `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.
8080
* `main_threshold` - (Optional) Whether this notification channel is used for the main threshold of the alert. Default: `true`.
8181
* `warning_threshold` - (Optional) Whether this notification channel is used for the warning threshold of the alert. Default: `false`.
8282

website/docs/r/monitor_alert_v2_downtime.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ It is a list of objects with the following fields:
6464
* `id` - (Required) The ID of the notification channel.
6565
* `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`.
6666
* `notify_on_resolve` - (Optional) Whether to send a notification when the alert is resolved. Default: `true`.
67-
* `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.
67+
* `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.
6868

6969
### `custom_notification`
7070

website/docs/r/monitor_alert_v2_event.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ It is a list of objects with the following fields:
7474
* `id` - (Required) The ID of the notification channel.
7575
* `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`.
7676
* `notify_on_resolve` - (Optional) Whether to send a notification when the alert is resolved. Default: `true`.
77-
* `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.
77+
* `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.
7878
* `main_threshold` - (Optional) Whether this notification channel is used for the main threshold of the alert. Default: `true`.
7979
* `warning_threshold` - (Optional) Whether this notification channel is used for the warning threshold of the alert. Default: `false`.
8080

website/docs/r/monitor_alert_v2_form_based_prometheus.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ It is a list of objects with the following fields:
5555
* `id` - (Required) The ID of the notification channel.
5656
* `renotify_every_minutes` - (Optional) the amount of minutes to wait before re sending the notification to this channel. `0` means no renotification enabled.
5757
* `notify_on_resolve` - (Optional) Whether to send a notification when the alert is resolved. Default: `true`.
58-
* `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.
58+
* `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.
5959
* `main_threshold` - (Optional) Whether this notification channel is used for the main threshold of the alert. Default: `true`.
6060
* `warning_threshold` - (Optional) Whether this notification channel is used for the warning threshold of the alert. Default: `false`.
6161

website/docs/r/monitor_alert_v2_group_outlier.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ It is a list of objects with the following fields:
7676
* `id` - (Required) The ID of the notification channel.
7777
* `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`.
7878
* `notify_on_resolve` - (Optional) Whether to send a notification when the alert is resolved. Default: `true`.
79-
* `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.
79+
* `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.
8080
* `main_threshold` - (Optional) Whether this notification channel is used for the main threshold of the alert. Default: `true`.
8181
* `warning_threshold` - (Optional) Whether this notification channel is used for the warning threshold of the alert. Default: `false`.
8282

website/docs/r/monitor_alert_v2_metric.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ It is a list of objects with the following fields:
9191
* `id` - (Required) The ID of the notification channel.
9292
* `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`.
9393
* `notify_on_resolve` - (Optional) Whether to send a notification when the alert is resolved. Default: `true`.
94-
* `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.
94+
* `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.
9595
* `main_threshold` - (Optional) Whether this notification channel is used for the main threshold of the alert. Default: `true`.
9696
* `warning_threshold` - (Optional) Whether this notification channel is used for the warning threshold of the alert. Default: `false`.
9797

0 commit comments

Comments
 (0)