Skip to content

Commit 9ce2c75

Browse files
authored
fix(alerts): properly handle info severity (#526)
1 parent c448de9 commit 9ce2c75

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

sysdig/resource_sysdig_monitor_alert_v2_common.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ func createAlertV2Schema(original map[string]*schema.Schema) map[string]*schema.
3838
Optional: true,
3939
Default: string(v2.AlertV2SeverityLow),
4040
ValidateFunc: validation.StringInSlice(AlertV2SeverityValues(), true),
41+
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
42+
return strings.EqualFold(old, new)
43+
},
4144
},
4245
"group": {
4346
Type: schema.TypeString,
@@ -201,10 +204,14 @@ func AlertLinkV2TypeValues() []string {
201204

202205
func buildAlertV2CommonStruct(d *schema.ResourceData) *v2.AlertV2Common {
203206
alert := &v2.AlertV2Common{
204-
Name: d.Get("name").(string),
205-
Type: "MANUAL",
206-
Severity: d.Get("severity").(string),
207-
Enabled: d.Get("enabled").(bool),
207+
Name: d.Get("name").(string),
208+
Type: "MANUAL",
209+
Enabled: d.Get("enabled").(bool),
210+
}
211+
212+
alert.Severity = strings.ToLower(d.Get("severity").(string))
213+
if alert.Severity == "info" {
214+
alert.Severity = "none"
208215
}
209216

210217
if description, ok := d.GetOk("description"); ok {
@@ -307,6 +314,9 @@ func updateAlertV2CommonState(d *schema.ResourceData, alert *v2.AlertV2Common) (
307314
_ = d.Set("name", alert.Name)
308315
_ = d.Set("description", alert.Description)
309316
_ = d.Set("severity", alert.Severity)
317+
if alert.Severity == "none" {
318+
_ = d.Set("severity", "info")
319+
}
310320

311321
// optional with defaults
312322
_ = d.Set("group", alert.Group)

sysdig/resource_sysdig_monitor_alert_v2_metric_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ func TestAccAlertV2Metric(t *testing.T) {
4242
{
4343
Config: alertV2MetricWithSeverity(rText()),
4444
},
45+
{
46+
Config: alertV2MetricWithSeverityInfo(rText()),
47+
},
4548
{
4649
Config: alertV2MetricWithGroupBy(rText()),
4750
},
@@ -202,6 +205,23 @@ resource "sysdig_monitor_alert_v2_metric" "sample" {
202205
`, name)
203206
}
204207

208+
func alertV2MetricWithSeverityInfo(name string) string {
209+
return fmt.Sprintf(`
210+
resource "sysdig_monitor_alert_v2_metric" "sample" {
211+
212+
name = "TERRAFORM TEST - METRICV2 %s"
213+
metric = "sysdig_container_cpu_used_percent"
214+
group_aggregation = "avg"
215+
time_aggregation = "avg"
216+
operator = ">="
217+
threshold = 50
218+
trigger_after_minutes = 15
219+
severity = "info"
220+
221+
}
222+
`, name)
223+
}
224+
205225
func alertV2MetricWithGroupBy(name string) string {
206226
return fmt.Sprintf(`
207227
resource "sysdig_monitor_alert_v2_metric" "sample" {

0 commit comments

Comments
 (0)