@@ -2,20 +2,15 @@ package alertconfiguration_test
2
2
3
3
import (
4
4
"fmt"
5
- "os"
6
5
"testing"
7
6
8
7
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
9
8
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
10
- "go.mongodb.org/atlas-sdk/v20231115007/admin"
11
9
)
12
10
13
11
func TestAccConfigDSAlertConfiguration_basic (t * testing.T ) {
14
12
var (
15
- alert = & admin.GroupAlertsConfig {}
16
- dataSourceName = "data.mongodbatlas_alert_configuration.test"
17
- orgID = os .Getenv ("MONGODB_ATLAS_ORG_ID" )
18
- projectName = acc .RandomProjectName ()
13
+ projectID = acc .ProjectIDExecution (t )
19
14
)
20
15
21
16
resource .ParallelTest (t , resource.TestCase {
@@ -24,10 +19,10 @@ func TestAccConfigDSAlertConfiguration_basic(t *testing.T) {
24
19
CheckDestroy : checkDestroy ,
25
20
Steps : []resource.TestStep {
26
21
{
27
- Config : configBasicDS (orgID , projectName ),
22
+ Config : configBasicDS (projectID ),
28
23
Check : resource .ComposeTestCheckFunc (
29
- checkExists (dataSourceName , alert ),
30
- resource .TestCheckResourceAttrSet (dataSourceName , "project_id" ),
24
+ checkExists (dataSourceName ),
25
+ resource .TestCheckResourceAttr (dataSourceName , "project_id" , projectID ),
31
26
resource .TestCheckResourceAttr (dataSourceName , "notification.#" , "1" ),
32
27
resource .TestCheckResourceAttrSet (dataSourceName , "notification.0.notifier_id" ),
33
28
resource .TestCheckResourceAttr (dataSourceName , "matcher.#" , "1" ),
@@ -41,10 +36,7 @@ func TestAccConfigDSAlertConfiguration_basic(t *testing.T) {
41
36
42
37
func TestAccConfigDSAlertConfiguration_withThreshold (t * testing.T ) {
43
38
var (
44
- alert = & admin.GroupAlertsConfig {}
45
- dataSourceName = "data.mongodbatlas_alert_configuration.test"
46
- orgID = os .Getenv ("MONGODB_ATLAS_ORG_ID" )
47
- projectName = acc .RandomProjectName ()
39
+ projectID = acc .ProjectIDExecution (t )
48
40
)
49
41
50
42
resource .ParallelTest (t , resource.TestCase {
@@ -53,11 +45,10 @@ func TestAccConfigDSAlertConfiguration_withThreshold(t *testing.T) {
53
45
CheckDestroy : checkDestroy ,
54
46
Steps : []resource.TestStep {
55
47
{
56
- Config : configWithThreshold (orgID , projectName , true , 1 ),
48
+ Config : configWithThreshold (projectID , true , 1 ),
57
49
Check : resource .ComposeTestCheckFunc (
58
- checkExists (dataSourceName , alert ),
59
- resource .TestCheckResourceAttrSet (dataSourceName , "project_id" ),
60
- resource .TestCheckResourceAttrSet (dataSourceName , "project_id" ),
50
+ checkExists (dataSourceName ),
51
+ resource .TestCheckResourceAttr (dataSourceName , "project_id" , projectID ),
61
52
resource .TestCheckResourceAttr (dataSourceName , "notification.#" , "1" ),
62
53
resource .TestCheckResourceAttr (dataSourceName , "matcher.#" , "1" ),
63
54
resource .TestCheckResourceAttr (dataSourceName , "metric_threshold_config.#" , "0" ),
@@ -70,11 +61,8 @@ func TestAccConfigDSAlertConfiguration_withThreshold(t *testing.T) {
70
61
71
62
func TestAccConfigDSAlertConfiguration_withOutput (t * testing.T ) {
72
63
var (
73
- alert = & admin.GroupAlertsConfig {}
74
- dataSourceName = "data.mongodbatlas_alert_configuration.test"
75
- orgID = os .Getenv ("MONGODB_ATLAS_ORG_ID" )
76
- projectName = acc .RandomProjectName ()
77
- outputLabel = "resource_import"
64
+ projectID = acc .ProjectIDExecution (t )
65
+ outputLabel = "resource_import"
78
66
)
79
67
80
68
resource .ParallelTest (t , resource.TestCase {
@@ -83,11 +71,10 @@ func TestAccConfigDSAlertConfiguration_withOutput(t *testing.T) {
83
71
CheckDestroy : checkDestroy ,
84
72
Steps : []resource.TestStep {
85
73
{
86
- Config : configWithOutputs (orgID , projectName , outputLabel ),
74
+ Config : configWithOutputs (projectID , outputLabel ),
87
75
Check : resource .ComposeTestCheckFunc (
88
- checkExists (dataSourceName , alert ),
89
- resource .TestCheckResourceAttrSet (dataSourceName , "project_id" ),
90
- resource .TestCheckResourceAttrSet (dataSourceName , "project_id" ),
76
+ checkExists (dataSourceName ),
77
+ resource .TestCheckResourceAttr (dataSourceName , "project_id" , projectID ),
91
78
resource .TestCheckResourceAttr (dataSourceName , "notification.#" , "1" ),
92
79
resource .TestCheckResourceAttr (dataSourceName , "output.0.label" , outputLabel ),
93
80
resource .TestCheckResourceAttr (dataSourceName , "output.0.type" , "resource_import" ),
@@ -103,37 +90,30 @@ func TestAccConfigDSAlertConfiguration_withOutput(t *testing.T) {
103
90
104
91
func TestAccConfigDSAlertConfiguration_withPagerDuty (t * testing.T ) {
105
92
var (
106
- alert = & admin.GroupAlertsConfig {}
107
- dataSourceName = "data.mongodbatlas_alert_configuration.test"
108
- orgID = os .Getenv ("MONGODB_ATLAS_ORG_ID" )
109
- projectName = acc .RandomProjectName ()
110
- serviceKey = dummy32CharKey
93
+ projectID = acc .ProjectIDExecution (t )
94
+ serviceKey = dummy32CharKey
111
95
)
112
96
113
- resource .Test (t , resource.TestCase {
97
+ resource .ParallelTest (t , resource.TestCase {
114
98
PreCheck : func () { acc .PreCheckBasic (t ) },
115
99
ProtoV6ProviderFactories : acc .TestAccProviderV6Factories ,
116
100
CheckDestroy : checkDestroy ,
117
101
Steps : []resource.TestStep {
118
102
{
119
- Config : configWithPagerDutyDS (orgID , projectName , serviceKey , true ),
103
+ Config : configWithPagerDutyDS (projectID , serviceKey , true ),
120
104
Check : resource .ComposeTestCheckFunc (
121
- checkExists (dataSourceName , alert ),
122
- resource .TestCheckResourceAttrSet (dataSourceName , "project_id" ),
105
+ checkExists (dataSourceName ),
106
+ resource .TestCheckResourceAttr (dataSourceName , "project_id" , projectID ),
123
107
),
124
108
},
125
109
},
126
110
})
127
111
}
128
112
129
- func configBasicDS (orgID , projectName string ) string {
113
+ func configBasicDS (projectID string ) string {
130
114
return fmt .Sprintf (`
131
- resource "mongodbatlas_project" "test" {
132
- name = %[2]q
133
- org_id = %[1]q
134
- }
135
115
resource "mongodbatlas_alert_configuration" "test" {
136
- project_id = mongodbatlas_project.test.id
116
+ project_id = %[1]q
137
117
event_type = "OUTSIDE_METRIC_THRESHOLD"
138
118
enabled = true
139
119
@@ -161,22 +141,18 @@ func configBasicDS(orgID, projectName string) string {
161
141
}
162
142
163
143
data "mongodbatlas_alert_configuration" "test" {
164
- project_id = "${ mongodbatlas_alert_configuration.test.project_id}"
165
- alert_configuration_id = "${ mongodbatlas_alert_configuration.test.id}"
144
+ project_id = mongodbatlas_alert_configuration.test.project_id
145
+ alert_configuration_id = mongodbatlas_alert_configuration.test.id
166
146
}
167
- ` , orgID , projectName )
147
+ ` , projectID )
168
148
}
169
149
170
- func configWithThreshold (orgID , projectName string , enabled bool , threshold float64 ) string {
150
+ func configWithThreshold (projectID string , enabled bool , threshold float64 ) string {
171
151
return fmt .Sprintf (`
172
- resource "mongodbatlas_project" "test" {
173
- name = %[2]q
174
- org_id = %[1]q
175
- }
176
152
resource "mongodbatlas_alert_configuration" "test" {
177
- project_id = mongodbatlas_project.test.id
153
+ project_id = %[1]q
154
+ enabled = %[2]t
178
155
event_type = "REPLICATION_OPLOG_WINDOW_RUNNING_OUT"
179
- enabled = "%[3]t"
180
156
181
157
notification {
182
158
type_name = "GROUP"
@@ -196,25 +172,21 @@ func configWithThreshold(orgID, projectName string, enabled bool, threshold floa
196
172
threshold_config {
197
173
operator = "LESS_THAN"
198
174
units = "HOURS"
199
- threshold = %[4 ]f
175
+ threshold = %[3 ]f
200
176
}
201
177
}
202
178
203
179
data "mongodbatlas_alert_configuration" "test" {
204
- project_id = "${ mongodbatlas_alert_configuration.test.project_id}"
205
- alert_configuration_id = "${ mongodbatlas_alert_configuration.test.id}"
180
+ project_id = mongodbatlas_alert_configuration.test.project_id
181
+ alert_configuration_id = mongodbatlas_alert_configuration.test.id
206
182
}
207
- ` , orgID , projectName , enabled , threshold )
183
+ ` , projectID , enabled , threshold )
208
184
}
209
185
210
- func configWithOutputs (orgID , projectName , outputLabel string ) string {
186
+ func configWithOutputs (projectID , outputLabel string ) string {
211
187
return fmt .Sprintf (`
212
- resource "mongodbatlas_project" "test" {
213
- name = %[2]q
214
- org_id = %[1]q
215
- }
216
188
resource "mongodbatlas_alert_configuration" "test" {
217
- project_id = mongodbatlas_project.test.id
189
+ project_id = %[1]q
218
190
219
191
event_type = "NO_PRIMARY"
220
192
enabled = true
@@ -230,42 +202,38 @@ func configWithOutputs(orgID, projectName, outputLabel string) string {
230
202
}
231
203
232
204
data "mongodbatlas_alert_configuration" "test" {
233
- project_id = "${ mongodbatlas_alert_configuration.test.project_id}"
234
- alert_configuration_id = "${ mongodbatlas_alert_configuration.test.id}"
205
+ project_id = mongodbatlas_alert_configuration.test.project_id
206
+ alert_configuration_id = mongodbatlas_alert_configuration.test.id
235
207
236
208
output {
237
209
type = "resource_import"
238
- label = %[3 ]q
210
+ label = %[2 ]q
239
211
}
240
212
output {
241
213
type = "resource_hcl"
242
- label = %[3 ]q
214
+ label = %[2 ]q
243
215
}
244
216
}
245
- ` , orgID , projectName , outputLabel )
217
+ ` , projectID , outputLabel )
246
218
}
247
219
248
- func configWithPagerDutyDS (orgID , projectName , serviceKey string , enabled bool ) string {
220
+ func configWithPagerDutyDS (projectID , serviceKey string , enabled bool ) string {
249
221
return fmt .Sprintf (`
250
- resource "mongodbatlas_project" "test" {
251
- name = %[2]q
252
- org_id = %[1]q
253
- }
254
- resource "mongodbatlas_alert_configuration" "test" {
255
- project_id = mongodbatlas_project.test.id
256
- event_type = "NO_PRIMARY"
257
- enabled = "%[4]t"
222
+ resource "mongodbatlas_alert_configuration" "test" {
223
+ project_id = %[1]q
224
+ enabled = "%[3]t"
225
+ event_type = "NO_PRIMARY"
258
226
259
- notification {
260
- type_name = "PAGER_DUTY"
261
- service_key = %[3 ]q
262
- delay_min = 0
263
- }
264
- }
227
+ notification {
228
+ type_name = "PAGER_DUTY"
229
+ service_key = %[2 ]q
230
+ delay_min = 0
231
+ }
232
+ }
265
233
266
- data "mongodbatlas_alert_configuration" "test" {
267
- project_id = "${ mongodbatlas_alert_configuration.test.project_id}"
268
- alert_configuration_id = "${ mongodbatlas_alert_configuration.test.id}"
269
- }
270
- ` , orgID , projectName , serviceKey , enabled )
234
+ data "mongodbatlas_alert_configuration" "test" {
235
+ project_id = mongodbatlas_alert_configuration.test.project_id
236
+ alert_configuration_id = mongodbatlas_alert_configuration.test.id
237
+ }
238
+ ` , projectID , serviceKey , enabled )
271
239
}
0 commit comments