Skip to content

Commit dbe9488

Browse files
authored
fix(alerts): remove hardcoded ids in tests (#284)
1 parent 8d92c94 commit dbe9488

File tree

1 file changed

+61
-9
lines changed

1 file changed

+61
-9
lines changed

sysdig/resource_sysdig_monitor_alert_v2_metric_test.go

Lines changed: 61 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ resource "sysdig_monitor_alert_v2_metric" "sample" {
136136

137137
func alertV2MetricWithNotificationChannels(name string) string {
138138
return fmt.Sprintf(`
139+
resource "sysdig_monitor_notification_channel_email" "nc_email1" {
140+
name = "%s1"
141+
recipients = ["[email protected]"]
142+
}
143+
144+
resource "sysdig_monitor_notification_channel_email" "nc_email2" {
145+
name = "%s2"
146+
recipients = ["[email protected]"]
147+
}
148+
139149
resource "sysdig_monitor_alert_v2_metric" "sample" {
140150
141151
name = "TERRAFORM TEST - METRICV2 %s"
@@ -147,15 +157,15 @@ resource "sysdig_monitor_alert_v2_metric" "sample" {
147157
trigger_after_minutes = 15
148158
enabled = false
149159
notification_channels {
150-
id = 47160
160+
id = sysdig_monitor_notification_channel_email.nc_email1.id
151161
notify_on_resolve = false
152162
}
153163
notification_channels {
154-
id = 47163
164+
id = sysdig_monitor_notification_channel_email.nc_email2.id
155165
renotify_every_minutes = 30
156166
}
157167
}
158-
`, name)
168+
`, name, name, name)
159169
}
160170

161171
func alertV2MetricWithDescription(name string) string {
@@ -267,8 +277,40 @@ resource "sysdig_monitor_alert_v2_metric" "sample" {
267277

268278
func alertV2MetricWithLink(name string) string {
269279
return fmt.Sprintf(`
270-
resource "sysdig_monitor_alert_v2_metric" "sample" {
280+
resource "sysdig_monitor_dashboard" "dashboard" {
281+
name = "TERRAFORM TEST - METRIC %s"
282+
description = "TERRAFORM TEST - METRIC %s"
283+
284+
panel {
285+
pos_x = 0
286+
pos_y = 0
287+
width = 12 # Maximum size: 24
288+
height = 6
289+
type = "timechart"
290+
name = "example panel"
291+
description = "description"
292+
293+
legend {
294+
show_current = true
295+
position = "bottom"
296+
layout = "inline"
297+
}
298+
299+
query {
300+
promql = "avg(avg_over_time(sysdig_host_cpu_used_percent[$__interval]))"
301+
unit = "percent"
302+
303+
format {
304+
display_format = "auto"
305+
input_format = "0-100"
306+
y_axis = "auto"
307+
null_value_display_mode = "nullGap"
308+
}
309+
}
310+
}
311+
}
271312
313+
resource "sysdig_monitor_alert_v2_metric" "sample" {
272314
name = "TERRAFORM TEST - METRICV2 %s"
273315
metric = "sysdig_container_cpu_used_percent"
274316
group_aggregation = "avg"
@@ -282,10 +324,10 @@ resource "sysdig_monitor_alert_v2_metric" "sample" {
282324
}
283325
link {
284326
type = "dashboard"
285-
id = "218044"
327+
id = sysdig_monitor_dashboard.dashboard.id
286328
}
287329
}
288-
`, name)
330+
`, name, name, name)
289331
}
290332

291333
func alertV2MetricWithEnabled(name string) string {
@@ -307,6 +349,16 @@ resource "sysdig_monitor_alert_v2_metric" "sample" {
307349

308350
func alertV2MetricWithWarningThreshold(name string) string {
309351
return fmt.Sprintf(`
352+
resource "sysdig_monitor_notification_channel_email" "nc_email1" {
353+
name = "%s1"
354+
recipients = ["[email protected]"]
355+
}
356+
357+
resource "sysdig_monitor_notification_channel_email" "nc_email2" {
358+
name = "%s2"
359+
recipients = ["[email protected]"]
360+
}
361+
310362
resource "sysdig_monitor_alert_v2_metric" "sample" {
311363
312364
name = "TERRAFORM TEST - METRICV2 %s"
@@ -319,12 +371,12 @@ resource "sysdig_monitor_alert_v2_metric" "sample" {
319371
enabled = false
320372
warning_threshold = 10
321373
notification_channels {
322-
id = 47160
374+
id = sysdig_monitor_notification_channel_email.nc_email1.id
323375
}
324376
notification_channels {
325-
id = 47163
377+
id = sysdig_monitor_notification_channel_email.nc_email2.id
326378
warning_threshold = true
327379
}
328380
}
329-
`, name)
381+
`, name, name, name)
330382
}

0 commit comments

Comments
 (0)