-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathresource_sysdig_monitor_silence_rule_test.go
More file actions
137 lines (127 loc) · 3.89 KB
/
resource_sysdig_monitor_silence_rule_test.go
File metadata and controls
137 lines (127 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//go:build tf_acc_sysdig_monitor || tf_acc_ibm_monitor || tf_acc_onprem_monitor
package sysdig_test
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/draios/terraform-provider-sysdig/sysdig"
)
func TestAccMonitorSilenceRule(t *testing.T) {
rText := func() string { return acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) }
resource.ParallelTest(t, resource.TestCase{
PreCheck: sysdigOrIBMMonitorPreCheck(t),
ProviderFactories: map[string]func() (*schema.Provider, error){
"sysdig": func() (*schema.Provider, error) {
return sysdig.Provider(), nil
},
},
Steps: []resource.TestStep{
{
Config: monitorSilenceRuleWithName(rText()),
},
{
ResourceName: "sysdig_monitor_silence_rule.sample1",
ImportState: true,
ImportStateVerify: true,
},
{
Config: monitorSilenceRuleWithAlertIds(rText()),
},
{
ResourceName: "sysdig_monitor_silence_rule.sample2",
ImportState: true,
ImportStateVerify: true,
},
{
Config: monitorSilenceRuleWithAlertIdsAndScope(rText()),
},
{
ResourceName: "sysdig_monitor_silence_rule.sample3",
ImportState: true,
ImportStateVerify: true,
},
{
Config: monitorSilenceRuleWithNotificationChannels(rText()),
},
{
ResourceName: "sysdig_monitor_silence_rule.sample4",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func monitorSilenceRuleWithName(name string) string {
return fmt.Sprintf(`
resource "sysdig_monitor_silence_rule" "sample1" {
name = "Example Silence Rule %s"
enabled = false
start_ts = 1691168134153
duration_seconds = 3600
scope = "container.name in (\"test\")"
}`, name)
}
func monitorSilenceRuleWithAlertIds(name string) string {
return fmt.Sprintf(`
resource "sysdig_monitor_alert_v2_prometheus" "sample1" {
name = "TERRAFORM TEST - PROMQL %s 1"
query = "up{kube_cluster_name=\"asd\"}"
duration_seconds = 60
enabled = false
}
resource "sysdig_monitor_alert_v2_prometheus" "sample2" {
name = "TERRAFORM TEST - PROMQL %s 2"
query = "up{kube_cluster_name=\"asd\"}"
duration_seconds = 60
enabled = false
}
resource "sysdig_monitor_silence_rule" "sample2" {
name = "Example Silence Rule %s"
enabled = false
start_ts = 1691168134153
duration_seconds = 3600
alert_ids = [ sysdig_monitor_alert_v2_prometheus.sample1.id, sysdig_monitor_alert_v2_prometheus.sample2.id ]
}`, name, name, name)
}
func monitorSilenceRuleWithAlertIdsAndScope(name string) string {
return fmt.Sprintf(`
resource "sysdig_monitor_alert_v2_prometheus" "sample3" {
name = "TERRAFORM TEST - PROMQL %s 3"
query = "up{kube_cluster_name=\"asd\"}"
duration_seconds = 60
enabled = false
}
resource "sysdig_monitor_alert_v2_prometheus" "sample4" {
name = "TERRAFORM TEST - PROMQL %s 4"
query = "up{kube_cluster_name=\"asd\"}"
duration_seconds = 60
enabled = false
}
resource "sysdig_monitor_silence_rule" "sample3" {
name = "Example Silence Rule %s"
enabled = false
start_ts = 1691168134153
duration_seconds = 3600
scope = "container.name in (\"test\")"
alert_ids = [ sysdig_monitor_alert_v2_prometheus.sample3.id, sysdig_monitor_alert_v2_prometheus.sample4.id ]
}`, name, name, name)
}
func monitorSilenceRuleWithNotificationChannels(name string) string {
return fmt.Sprintf(`
resource "sysdig_monitor_notification_channel_webhook" "sample-webhook" {
name = "Example Channel %s - Webhook"
enabled = false
url = "https://example.com/"
send_test_notification = false
}
resource "sysdig_monitor_silence_rule" "sample4" {
name = "Example Silence Rule %s"
enabled = false
start_ts = 1691168134153
duration_seconds = 3600
scope = "container.name in (\"test\")"
notification_channel_ids = [sysdig_monitor_notification_channel_webhook.sample-webhook.id]
}`, name, name)
}