@@ -2,20 +2,15 @@ package alertconfiguration_test
22
33import (
44 "fmt"
5- "os"
65 "testing"
76
87 "github.com/hashicorp/terraform-plugin-testing/helper/resource"
98 "github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
10- "go.mongodb.org/atlas-sdk/v20231115007/admin"
119)
1210
1311func TestAccConfigDSAlertConfiguration_basic (t * testing.T ) {
1412 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 )
1914 )
2015
2116 resource .ParallelTest (t , resource.TestCase {
@@ -24,10 +19,10 @@ func TestAccConfigDSAlertConfiguration_basic(t *testing.T) {
2419 CheckDestroy : checkDestroy ,
2520 Steps : []resource.TestStep {
2621 {
27- Config : configBasicDS (orgID , projectName ),
22+ Config : configBasicDS (projectID ),
2823 Check : resource .ComposeTestCheckFunc (
29- checkExists (dataSourceName , alert ),
30- resource .TestCheckResourceAttrSet (dataSourceName , "project_id" ),
24+ checkExists (dataSourceName ),
25+ resource .TestCheckResourceAttr (dataSourceName , "project_id" , projectID ),
3126 resource .TestCheckResourceAttr (dataSourceName , "notification.#" , "1" ),
3227 resource .TestCheckResourceAttrSet (dataSourceName , "notification.0.notifier_id" ),
3328 resource .TestCheckResourceAttr (dataSourceName , "matcher.#" , "1" ),
@@ -41,10 +36,7 @@ func TestAccConfigDSAlertConfiguration_basic(t *testing.T) {
4136
4237func TestAccConfigDSAlertConfiguration_withThreshold (t * testing.T ) {
4338 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 )
4840 )
4941
5042 resource .ParallelTest (t , resource.TestCase {
@@ -53,11 +45,10 @@ func TestAccConfigDSAlertConfiguration_withThreshold(t *testing.T) {
5345 CheckDestroy : checkDestroy ,
5446 Steps : []resource.TestStep {
5547 {
56- Config : configWithThreshold (orgID , projectName , true , 1 ),
48+ Config : configWithThreshold (projectID , true , 1 ),
5749 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 ),
6152 resource .TestCheckResourceAttr (dataSourceName , "notification.#" , "1" ),
6253 resource .TestCheckResourceAttr (dataSourceName , "matcher.#" , "1" ),
6354 resource .TestCheckResourceAttr (dataSourceName , "metric_threshold_config.#" , "0" ),
@@ -70,11 +61,8 @@ func TestAccConfigDSAlertConfiguration_withThreshold(t *testing.T) {
7061
7162func TestAccConfigDSAlertConfiguration_withOutput (t * testing.T ) {
7263 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"
7866 )
7967
8068 resource .ParallelTest (t , resource.TestCase {
@@ -83,11 +71,10 @@ func TestAccConfigDSAlertConfiguration_withOutput(t *testing.T) {
8371 CheckDestroy : checkDestroy ,
8472 Steps : []resource.TestStep {
8573 {
86- Config : configWithOutputs (orgID , projectName , outputLabel ),
74+ Config : configWithOutputs (projectID , outputLabel ),
8775 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 ),
9178 resource .TestCheckResourceAttr (dataSourceName , "notification.#" , "1" ),
9279 resource .TestCheckResourceAttr (dataSourceName , "output.0.label" , outputLabel ),
9380 resource .TestCheckResourceAttr (dataSourceName , "output.0.type" , "resource_import" ),
@@ -103,37 +90,30 @@ func TestAccConfigDSAlertConfiguration_withOutput(t *testing.T) {
10390
10491func TestAccConfigDSAlertConfiguration_withPagerDuty (t * testing.T ) {
10592 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
11195 )
11296
113- resource .Test (t , resource.TestCase {
97+ resource .ParallelTest (t , resource.TestCase {
11498 PreCheck : func () { acc .PreCheckBasic (t ) },
11599 ProtoV6ProviderFactories : acc .TestAccProviderV6Factories ,
116100 CheckDestroy : checkDestroy ,
117101 Steps : []resource.TestStep {
118102 {
119- Config : configWithPagerDutyDS (orgID , projectName , serviceKey , true ),
103+ Config : configWithPagerDutyDS (projectID , serviceKey , true ),
120104 Check : resource .ComposeTestCheckFunc (
121- checkExists (dataSourceName , alert ),
122- resource .TestCheckResourceAttrSet (dataSourceName , "project_id" ),
105+ checkExists (dataSourceName ),
106+ resource .TestCheckResourceAttr (dataSourceName , "project_id" , projectID ),
123107 ),
124108 },
125109 },
126110 })
127111}
128112
129- func configBasicDS (orgID , projectName string ) string {
113+ func configBasicDS (projectID string ) string {
130114 return fmt .Sprintf (`
131- resource "mongodbatlas_project" "test" {
132- name = %[2]q
133- org_id = %[1]q
134- }
135115 resource "mongodbatlas_alert_configuration" "test" {
136- project_id = mongodbatlas_project.test.id
116+ project_id = %[1]q
137117 event_type = "OUTSIDE_METRIC_THRESHOLD"
138118 enabled = true
139119
@@ -161,22 +141,18 @@ func configBasicDS(orgID, projectName string) string {
161141 }
162142
163143 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
166146 }
167- ` , orgID , projectName )
147+ ` , projectID )
168148}
169149
170- func configWithThreshold (orgID , projectName string , enabled bool , threshold float64 ) string {
150+ func configWithThreshold (projectID string , enabled bool , threshold float64 ) string {
171151 return fmt .Sprintf (`
172- resource "mongodbatlas_project" "test" {
173- name = %[2]q
174- org_id = %[1]q
175- }
176152 resource "mongodbatlas_alert_configuration" "test" {
177- project_id = mongodbatlas_project.test.id
153+ project_id = %[1]q
154+ enabled = %[2]t
178155 event_type = "REPLICATION_OPLOG_WINDOW_RUNNING_OUT"
179- enabled = "%[3]t"
180156
181157 notification {
182158 type_name = "GROUP"
@@ -196,25 +172,21 @@ func configWithThreshold(orgID, projectName string, enabled bool, threshold floa
196172 threshold_config {
197173 operator = "LESS_THAN"
198174 units = "HOURS"
199- threshold = %[4 ]f
175+ threshold = %[3 ]f
200176 }
201177 }
202178
203179 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
206182 }
207- ` , orgID , projectName , enabled , threshold )
183+ ` , projectID , enabled , threshold )
208184}
209185
210- func configWithOutputs (orgID , projectName , outputLabel string ) string {
186+ func configWithOutputs (projectID , outputLabel string ) string {
211187 return fmt .Sprintf (`
212- resource "mongodbatlas_project" "test" {
213- name = %[2]q
214- org_id = %[1]q
215- }
216188 resource "mongodbatlas_alert_configuration" "test" {
217- project_id = mongodbatlas_project.test.id
189+ project_id = %[1]q
218190
219191 event_type = "NO_PRIMARY"
220192 enabled = true
@@ -230,42 +202,38 @@ func configWithOutputs(orgID, projectName, outputLabel string) string {
230202 }
231203
232204 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
235207
236208 output {
237209 type = "resource_import"
238- label = %[3 ]q
210+ label = %[2 ]q
239211 }
240212 output {
241213 type = "resource_hcl"
242- label = %[3 ]q
214+ label = %[2 ]q
243215 }
244216 }
245- ` , orgID , projectName , outputLabel )
217+ ` , projectID , outputLabel )
246218}
247219
248- func configWithPagerDutyDS (orgID , projectName , serviceKey string , enabled bool ) string {
220+ func configWithPagerDutyDS (projectID , serviceKey string , enabled bool ) string {
249221 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"
258226
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+ }
265233
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 )
271239}
0 commit comments