@@ -17,19 +17,20 @@ import (
17
17
)
18
18
19
19
func TestAccCloudWatchCompositeAlarm_basic (t * testing.T ) {
20
+ ctx := acctest .Context (t )
20
21
suffix := sdkacctest .RandString (8 )
21
22
resourceName := "aws_cloudwatch_composite_alarm.test"
22
23
23
24
resource .ParallelTest (t , resource.TestCase {
24
25
PreCheck : func () { acctest .PreCheck (t ) },
25
26
ErrorCheck : acctest .ErrorCheck (t , cloudwatch .EndpointsID ),
26
27
ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
27
- CheckDestroy : testAccCheckCompositeAlarmDestroy ,
28
+ CheckDestroy : testAccCheckCompositeAlarmDestroy ( ctx ) ,
28
29
Steps : []resource.TestStep {
29
30
{
30
31
Config : testAccCompositeAlarmConfig_basic (suffix ),
31
32
Check : resource .ComposeTestCheckFunc (
32
- testAccCheckCompositeAlarmExists (resourceName ),
33
+ testAccCheckCompositeAlarmExists (ctx , resourceName ),
33
34
resource .TestCheckResourceAttr (resourceName , "actions_enabled" , "true" ),
34
35
resource .TestCheckResourceAttr (resourceName , "alarm_actions.#" , "0" ),
35
36
resource .TestCheckResourceAttr (resourceName , "alarm_description" , "" ),
@@ -51,19 +52,20 @@ func TestAccCloudWatchCompositeAlarm_basic(t *testing.T) {
51
52
}
52
53
53
54
func TestAccCloudWatchCompositeAlarm_disappears (t * testing.T ) {
55
+ ctx := acctest .Context (t )
54
56
suffix := sdkacctest .RandString (8 )
55
57
resourceName := "aws_cloudwatch_composite_alarm.test"
56
58
57
59
resource .ParallelTest (t , resource.TestCase {
58
60
PreCheck : func () { acctest .PreCheck (t ) },
59
61
ErrorCheck : acctest .ErrorCheck (t , cloudwatch .EndpointsID ),
60
62
ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
61
- CheckDestroy : testAccCheckCompositeAlarmDestroy ,
63
+ CheckDestroy : testAccCheckCompositeAlarmDestroy ( ctx ) ,
62
64
Steps : []resource.TestStep {
63
65
{
64
66
Config : testAccCompositeAlarmConfig_basic (suffix ),
65
67
Check : resource .ComposeTestCheckFunc (
66
- testAccCheckCompositeAlarmExists (resourceName ),
68
+ testAccCheckCompositeAlarmExists (ctx , resourceName ),
67
69
acctest .CheckResourceDisappears (acctest .Provider , tfcloudwatch .ResourceCompositeAlarm (), resourceName ),
68
70
),
69
71
ExpectNonEmptyPlan : true ,
@@ -73,19 +75,20 @@ func TestAccCloudWatchCompositeAlarm_disappears(t *testing.T) {
73
75
}
74
76
75
77
func TestAccCloudWatchCompositeAlarm_actionsEnabled (t * testing.T ) {
78
+ ctx := acctest .Context (t )
76
79
suffix := sdkacctest .RandString (8 )
77
80
resourceName := "aws_cloudwatch_composite_alarm.test"
78
81
79
82
resource .ParallelTest (t , resource.TestCase {
80
83
PreCheck : func () { acctest .PreCheck (t ) },
81
84
ErrorCheck : acctest .ErrorCheck (t , cloudwatch .EndpointsID ),
82
85
ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
83
- CheckDestroy : testAccCheckCompositeAlarmDestroy ,
86
+ CheckDestroy : testAccCheckCompositeAlarmDestroy ( ctx ) ,
84
87
Steps : []resource.TestStep {
85
88
{
86
89
Config : testAccCompositeAlarmConfig_actionsEnabled (false , suffix ),
87
90
Check : resource .ComposeTestCheckFunc (
88
- testAccCheckCompositeAlarmExists (resourceName ),
91
+ testAccCheckCompositeAlarmExists (ctx , resourceName ),
89
92
resource .TestCheckResourceAttr (resourceName , "actions_enabled" , "false" ),
90
93
),
91
94
},
@@ -97,7 +100,7 @@ func TestAccCloudWatchCompositeAlarm_actionsEnabled(t *testing.T) {
97
100
{
98
101
Config : testAccCompositeAlarmConfig_actionsEnabled (true , suffix ),
99
102
Check : resource .ComposeTestCheckFunc (
100
- testAccCheckCompositeAlarmExists (resourceName ),
103
+ testAccCheckCompositeAlarmExists (ctx , resourceName ),
101
104
resource .TestCheckResourceAttr (resourceName , "actions_enabled" , "true" ),
102
105
),
103
106
},
@@ -111,19 +114,20 @@ func TestAccCloudWatchCompositeAlarm_actionsEnabled(t *testing.T) {
111
114
}
112
115
113
116
func TestAccCloudWatchCompositeAlarm_alarmActions (t * testing.T ) {
117
+ ctx := acctest .Context (t )
114
118
suffix := sdkacctest .RandString (8 )
115
119
resourceName := "aws_cloudwatch_composite_alarm.test"
116
120
117
121
resource .ParallelTest (t , resource.TestCase {
118
122
PreCheck : func () { acctest .PreCheck (t ) },
119
123
ErrorCheck : acctest .ErrorCheck (t , cloudwatch .EndpointsID ),
120
124
ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
121
- CheckDestroy : testAccCheckCompositeAlarmDestroy ,
125
+ CheckDestroy : testAccCheckCompositeAlarmDestroy ( ctx ) ,
122
126
Steps : []resource.TestStep {
123
127
{
124
128
Config : testAccCompositeAlarmConfig_actions (suffix ),
125
129
Check : resource .ComposeTestCheckFunc (
126
- testAccCheckCompositeAlarmExists (resourceName ),
130
+ testAccCheckCompositeAlarmExists (ctx , resourceName ),
127
131
resource .TestCheckResourceAttr (resourceName , "alarm_actions.#" , "2" ),
128
132
),
129
133
},
@@ -135,7 +139,7 @@ func TestAccCloudWatchCompositeAlarm_alarmActions(t *testing.T) {
135
139
{
136
140
Config : testAccCompositeAlarmConfig_updateActions (suffix ),
137
141
Check : resource .ComposeTestCheckFunc (
138
- testAccCheckCompositeAlarmExists (resourceName ),
142
+ testAccCheckCompositeAlarmExists (ctx , resourceName ),
139
143
resource .TestCheckResourceAttr (resourceName , "alarm_actions.#" , "1" ),
140
144
),
141
145
},
@@ -147,7 +151,7 @@ func TestAccCloudWatchCompositeAlarm_alarmActions(t *testing.T) {
147
151
{
148
152
Config : testAccCompositeAlarmConfig_basic (suffix ),
149
153
Check : resource .ComposeTestCheckFunc (
150
- testAccCheckCompositeAlarmExists (resourceName ),
154
+ testAccCheckCompositeAlarmExists (ctx , resourceName ),
151
155
resource .TestCheckResourceAttr (resourceName , "alarm_actions.#" , "0" ),
152
156
),
153
157
},
@@ -161,19 +165,20 @@ func TestAccCloudWatchCompositeAlarm_alarmActions(t *testing.T) {
161
165
}
162
166
163
167
func TestAccCloudWatchCompositeAlarm_description (t * testing.T ) {
168
+ ctx := acctest .Context (t )
164
169
suffix := sdkacctest .RandString (8 )
165
170
resourceName := "aws_cloudwatch_composite_alarm.test"
166
171
167
172
resource .ParallelTest (t , resource.TestCase {
168
173
PreCheck : func () { acctest .PreCheck (t ) },
169
174
ErrorCheck : acctest .ErrorCheck (t , cloudwatch .EndpointsID ),
170
175
ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
171
- CheckDestroy : testAccCheckCompositeAlarmDestroy ,
176
+ CheckDestroy : testAccCheckCompositeAlarmDestroy ( ctx ) ,
172
177
Steps : []resource.TestStep {
173
178
{
174
179
Config : testAccCompositeAlarmConfig_description ("Test 1" , suffix ),
175
180
Check : resource .ComposeTestCheckFunc (
176
- testAccCheckCompositeAlarmExists (resourceName ),
181
+ testAccCheckCompositeAlarmExists (ctx , resourceName ),
177
182
resource .TestCheckResourceAttr (resourceName , "alarm_description" , "Test 1" ),
178
183
),
179
184
},
@@ -185,7 +190,7 @@ func TestAccCloudWatchCompositeAlarm_description(t *testing.T) {
185
190
{
186
191
Config : testAccCompositeAlarmConfig_description ("Test Updated" , suffix ),
187
192
Check : resource .ComposeTestCheckFunc (
188
- testAccCheckCompositeAlarmExists (resourceName ),
193
+ testAccCheckCompositeAlarmExists (ctx , resourceName ),
189
194
resource .TestCheckResourceAttr (resourceName , "alarm_description" , "Test Updated" ),
190
195
),
191
196
},
@@ -199,19 +204,20 @@ func TestAccCloudWatchCompositeAlarm_description(t *testing.T) {
199
204
}
200
205
201
206
func TestAccCloudWatchCompositeAlarm_insufficientDataActions (t * testing.T ) {
207
+ ctx := acctest .Context (t )
202
208
suffix := sdkacctest .RandString (8 )
203
209
resourceName := "aws_cloudwatch_composite_alarm.test"
204
210
205
211
resource .ParallelTest (t , resource.TestCase {
206
212
PreCheck : func () { acctest .PreCheck (t ) },
207
213
ErrorCheck : acctest .ErrorCheck (t , cloudwatch .EndpointsID ),
208
214
ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
209
- CheckDestroy : testAccCheckCompositeAlarmDestroy ,
215
+ CheckDestroy : testAccCheckCompositeAlarmDestroy ( ctx ) ,
210
216
Steps : []resource.TestStep {
211
217
{
212
218
Config : testAccCompositeAlarmConfig_insufficientDataActions (suffix ),
213
219
Check : resource .ComposeTestCheckFunc (
214
- testAccCheckCompositeAlarmExists (resourceName ),
220
+ testAccCheckCompositeAlarmExists (ctx , resourceName ),
215
221
resource .TestCheckResourceAttr (resourceName , "insufficient_data_actions.#" , "2" ),
216
222
),
217
223
},
@@ -223,7 +229,7 @@ func TestAccCloudWatchCompositeAlarm_insufficientDataActions(t *testing.T) {
223
229
{
224
230
Config : testAccCompositeAlarmConfig_updateInsufficientDataActions (suffix ),
225
231
Check : resource .ComposeTestCheckFunc (
226
- testAccCheckCompositeAlarmExists (resourceName ),
232
+ testAccCheckCompositeAlarmExists (ctx , resourceName ),
227
233
resource .TestCheckResourceAttr (resourceName , "insufficient_data_actions.#" , "1" ),
228
234
),
229
235
},
@@ -235,7 +241,7 @@ func TestAccCloudWatchCompositeAlarm_insufficientDataActions(t *testing.T) {
235
241
{
236
242
Config : testAccCompositeAlarmConfig_basic (suffix ),
237
243
Check : resource .ComposeTestCheckFunc (
238
- testAccCheckCompositeAlarmExists (resourceName ),
244
+ testAccCheckCompositeAlarmExists (ctx , resourceName ),
239
245
resource .TestCheckResourceAttr (resourceName , "insufficient_data_actions.#" , "0" ),
240
246
),
241
247
},
@@ -249,19 +255,20 @@ func TestAccCloudWatchCompositeAlarm_insufficientDataActions(t *testing.T) {
249
255
}
250
256
251
257
func TestAccCloudWatchCompositeAlarm_okActions (t * testing.T ) {
258
+ ctx := acctest .Context (t )
252
259
suffix := sdkacctest .RandString (8 )
253
260
resourceName := "aws_cloudwatch_composite_alarm.test"
254
261
255
262
resource .ParallelTest (t , resource.TestCase {
256
263
PreCheck : func () { acctest .PreCheck (t ) },
257
264
ErrorCheck : acctest .ErrorCheck (t , cloudwatch .EndpointsID ),
258
265
ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
259
- CheckDestroy : testAccCheckCompositeAlarmDestroy ,
266
+ CheckDestroy : testAccCheckCompositeAlarmDestroy ( ctx ) ,
260
267
Steps : []resource.TestStep {
261
268
{
262
269
Config : testAccCompositeAlarmConfig_okActions (suffix ),
263
270
Check : resource .ComposeTestCheckFunc (
264
- testAccCheckCompositeAlarmExists (resourceName ),
271
+ testAccCheckCompositeAlarmExists (ctx , resourceName ),
265
272
resource .TestCheckResourceAttr (resourceName , "ok_actions.#" , "2" ),
266
273
),
267
274
},
@@ -273,7 +280,7 @@ func TestAccCloudWatchCompositeAlarm_okActions(t *testing.T) {
273
280
{
274
281
Config : testAccCompositeAlarmConfig_updateOkActions (suffix ),
275
282
Check : resource .ComposeTestCheckFunc (
276
- testAccCheckCompositeAlarmExists (resourceName ),
283
+ testAccCheckCompositeAlarmExists (ctx , resourceName ),
277
284
resource .TestCheckResourceAttr (resourceName , "ok_actions.#" , "1" ),
278
285
),
279
286
},
@@ -285,7 +292,7 @@ func TestAccCloudWatchCompositeAlarm_okActions(t *testing.T) {
285
292
{
286
293
Config : testAccCompositeAlarmConfig_basic (suffix ),
287
294
Check : resource .ComposeTestCheckFunc (
288
- testAccCheckCompositeAlarmExists (resourceName ),
295
+ testAccCheckCompositeAlarmExists (ctx , resourceName ),
289
296
resource .TestCheckResourceAttr (resourceName , "ok_actions.#" , "0" ),
290
297
),
291
298
},
@@ -299,19 +306,20 @@ func TestAccCloudWatchCompositeAlarm_okActions(t *testing.T) {
299
306
}
300
307
301
308
func TestAccCloudWatchCompositeAlarm_allActions (t * testing.T ) {
309
+ ctx := acctest .Context (t )
302
310
suffix := sdkacctest .RandString (8 )
303
311
resourceName := "aws_cloudwatch_composite_alarm.test"
304
312
305
313
resource .ParallelTest (t , resource.TestCase {
306
314
PreCheck : func () { acctest .PreCheck (t ) },
307
315
ErrorCheck : acctest .ErrorCheck (t , cloudwatch .EndpointsID ),
308
316
ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
309
- CheckDestroy : testAccCheckCompositeAlarmDestroy ,
317
+ CheckDestroy : testAccCheckCompositeAlarmDestroy ( ctx ) ,
310
318
Steps : []resource.TestStep {
311
319
{
312
320
Config : testAccCompositeAlarmConfig_allActions (suffix ),
313
321
Check : resource .ComposeTestCheckFunc (
314
- testAccCheckCompositeAlarmExists (resourceName ),
322
+ testAccCheckCompositeAlarmExists (ctx , resourceName ),
315
323
resource .TestCheckResourceAttr (resourceName , "alarm_actions.#" , "1" ),
316
324
resource .TestCheckResourceAttr (resourceName , "insufficient_data_actions.#" , "1" ),
317
325
resource .TestCheckResourceAttr (resourceName , "ok_actions.#" , "1" ),
@@ -325,7 +333,7 @@ func TestAccCloudWatchCompositeAlarm_allActions(t *testing.T) {
325
333
{
326
334
Config : testAccCompositeAlarmConfig_basic (suffix ),
327
335
Check : resource .ComposeTestCheckFunc (
328
- testAccCheckCompositeAlarmExists (resourceName ),
336
+ testAccCheckCompositeAlarmExists (ctx , resourceName ),
329
337
resource .TestCheckResourceAttr (resourceName , "alarm_actions.#" , "0" ),
330
338
resource .TestCheckResourceAttr (resourceName , "insufficient_data_actions.#" , "0" ),
331
339
resource .TestCheckResourceAttr (resourceName , "ok_actions.#" , "0" ),
@@ -341,19 +349,20 @@ func TestAccCloudWatchCompositeAlarm_allActions(t *testing.T) {
341
349
}
342
350
343
351
func TestAccCloudWatchCompositeAlarm_updateAlarmRule (t * testing.T ) {
352
+ ctx := acctest .Context (t )
344
353
suffix := sdkacctest .RandString (8 )
345
354
resourceName := "aws_cloudwatch_composite_alarm.test"
346
355
347
356
resource .ParallelTest (t , resource.TestCase {
348
357
PreCheck : func () { acctest .PreCheck (t ) },
349
358
ErrorCheck : acctest .ErrorCheck (t , cloudwatch .EndpointsID ),
350
359
ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
351
- CheckDestroy : testAccCheckCompositeAlarmDestroy ,
360
+ CheckDestroy : testAccCheckCompositeAlarmDestroy ( ctx ) ,
352
361
Steps : []resource.TestStep {
353
362
{
354
363
Config : testAccCompositeAlarmConfig_basic (suffix ),
355
364
Check : resource .ComposeTestCheckFunc (
356
- testAccCheckCompositeAlarmExists (resourceName ),
365
+ testAccCheckCompositeAlarmExists (ctx , resourceName ),
357
366
),
358
367
},
359
368
{
@@ -364,7 +373,7 @@ func TestAccCloudWatchCompositeAlarm_updateAlarmRule(t *testing.T) {
364
373
{
365
374
Config : testAccCompositeAlarmConfig_updateRule (suffix ),
366
375
Check : resource .ComposeTestCheckFunc (
367
- testAccCheckCompositeAlarmExists (resourceName ),
376
+ testAccCheckCompositeAlarmExists (ctx , resourceName ),
368
377
resource .TestCheckResourceAttr (resourceName , "alarm_rule" , fmt .Sprintf ("ALARM(tf-test-metric-0-%[1]s)" , suffix )),
369
378
),
370
379
},
@@ -377,32 +386,34 @@ func TestAccCloudWatchCompositeAlarm_updateAlarmRule(t *testing.T) {
377
386
})
378
387
}
379
388
380
- func testAccCheckCompositeAlarmDestroy (s * terraform.State ) error {
381
- conn := acctest .Provider .Meta ().(* conns.AWSClient ).CloudWatchConn ()
389
+ func testAccCheckCompositeAlarmDestroy (ctx context.Context ) resource.TestCheckFunc {
390
+ return func (s * terraform.State ) error {
391
+ conn := acctest .Provider .Meta ().(* conns.AWSClient ).CloudWatchConn ()
382
392
383
- for _ , rs := range s .RootModule ().Resources {
384
- if rs .Type != "aws_cloudwatch_composite_alarm" {
385
- continue
386
- }
393
+ for _ , rs := range s .RootModule ().Resources {
394
+ if rs .Type != "aws_cloudwatch_composite_alarm" {
395
+ continue
396
+ }
387
397
388
- alarm , err := tfcloudwatch .FindCompositeAlarmByName (context . Background () , conn , rs .Primary .ID )
398
+ alarm , err := tfcloudwatch .FindCompositeAlarmByName (ctx , conn , rs .Primary .ID )
389
399
390
- if tfawserr .ErrCodeEquals (err , cloudwatch .ErrCodeResourceNotFound ) {
391
- continue
392
- }
393
- if err != nil {
394
- return fmt .Errorf ("error reading CloudWatch composite alarm (%s): %w" , rs .Primary .ID , err )
395
- }
400
+ if tfawserr .ErrCodeEquals (err , cloudwatch .ErrCodeResourceNotFound ) {
401
+ continue
402
+ }
403
+ if err != nil {
404
+ return fmt .Errorf ("error reading CloudWatch composite alarm (%s): %w" , rs .Primary .ID , err )
405
+ }
396
406
397
- if alarm != nil {
398
- return fmt .Errorf ("CloudWatch composite alarm (%s) still exists" , rs .Primary .ID )
407
+ if alarm != nil {
408
+ return fmt .Errorf ("CloudWatch composite alarm (%s) still exists" , rs .Primary .ID )
409
+ }
399
410
}
400
- }
401
411
402
- return nil
412
+ return nil
413
+ }
403
414
}
404
415
405
- func testAccCheckCompositeAlarmExists (resourceName string ) resource.TestCheckFunc {
416
+ func testAccCheckCompositeAlarmExists (ctx context. Context , resourceName string ) resource.TestCheckFunc {
406
417
return func (s * terraform.State ) error {
407
418
rs , ok := s .RootModule ().Resources [resourceName ]
408
419
if ! ok {
@@ -415,7 +426,7 @@ func testAccCheckCompositeAlarmExists(resourceName string) resource.TestCheckFun
415
426
416
427
conn := acctest .Provider .Meta ().(* conns.AWSClient ).CloudWatchConn ()
417
428
418
- alarm , err := tfcloudwatch .FindCompositeAlarmByName (context . Background () , conn , rs .Primary .ID )
429
+ alarm , err := tfcloudwatch .FindCompositeAlarmByName (ctx , conn , rs .Primary .ID )
419
430
420
431
if err != nil {
421
432
return fmt .Errorf ("error reading CloudWatch composite alarm (%s): %w" , rs .Primary .ID , err )
0 commit comments