@@ -33,7 +33,7 @@ func TestAccKMSReplicaKey_basic(t *testing.T) {
33
33
acctest .PreCheckMultipleRegion (t , 2 )
34
34
},
35
35
ErrorCheck : acctest .ErrorCheck (t , names .KMSServiceID ),
36
- ProtoV5ProviderFactories : acctest .ProtoV5FactoriesAlternate ( ctx , t ) ,
36
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
37
37
CheckDestroy : testAccCheckKeyDestroy (ctx ),
38
38
Steps : []resource.TestStep {
39
39
{
@@ -77,7 +77,7 @@ func TestAccKMSReplicaKey_disappears(t *testing.T) {
77
77
acctest .PreCheckMultipleRegion (t , 2 )
78
78
},
79
79
ErrorCheck : acctest .ErrorCheck (t , names .KMSServiceID ),
80
- ProtoV5ProviderFactories : acctest .ProtoV5FactoriesAlternate ( ctx , t ) ,
80
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
81
81
CheckDestroy : testAccCheckKeyDestroy (ctx ),
82
82
Steps : []resource.TestStep {
83
83
{
@@ -107,7 +107,7 @@ func TestAccKMSReplicaKey_descriptionAndEnabled(t *testing.T) {
107
107
acctest .PreCheckMultipleRegion (t , 2 )
108
108
},
109
109
ErrorCheck : acctest .ErrorCheck (t , names .KMSServiceID ),
110
- ProtoV5ProviderFactories : acctest .ProtoV5FactoriesAlternate ( ctx , t ) ,
110
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
111
111
CheckDestroy : testAccCheckKeyDestroy (ctx ),
112
112
Steps : []resource.TestStep {
113
113
{
@@ -158,7 +158,7 @@ func TestAccKMSReplicaKey_policy(t *testing.T) {
158
158
acctest .PreCheckMultipleRegion (t , 2 )
159
159
},
160
160
ErrorCheck : acctest .ErrorCheck (t , names .KMSServiceID ),
161
- ProtoV5ProviderFactories : acctest .ProtoV5FactoriesAlternate ( ctx , t ) ,
161
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
162
162
CheckDestroy : testAccCheckKeyDestroy (ctx ),
163
163
Steps : []resource.TestStep {
164
164
{
@@ -199,7 +199,7 @@ func TestAccKMSReplicaKey_twoReplicas(t *testing.T) {
199
199
acctest .PreCheckMultipleRegion (t , 3 )
200
200
},
201
201
ErrorCheck : acctest .ErrorCheck (t , names .KMSServiceID ),
202
- ProtoV5ProviderFactories : acctest .ProtoV5FactoriesMultipleRegions ( ctx , t , 3 ) ,
202
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
203
203
CheckDestroy : testAccCheckKeyDestroy (ctx ),
204
204
Steps : []resource.TestStep {
205
205
{
@@ -212,6 +212,51 @@ func TestAccKMSReplicaKey_twoReplicas(t *testing.T) {
212
212
})
213
213
}
214
214
215
+ func TestAccKMSReplicaKey_multipleProviders (t * testing.T ) {
216
+ ctx := acctest .Context (t )
217
+ var key awstypes.KeyMetadata
218
+ rName := sdkacctest .RandomWithPrefix (acctest .ResourcePrefix )
219
+ primaryKeyResourceName := "aws_kms_key.test"
220
+ resourceName := "aws_kms_replica_key.test"
221
+
222
+ resource .ParallelTest (t , resource.TestCase {
223
+ PreCheck : func () {
224
+ acctest .PreCheck (ctx , t )
225
+ acctest .PreCheckMultipleRegion (t , 2 )
226
+ },
227
+ ErrorCheck : acctest .ErrorCheck (t , names .KMSServiceID ),
228
+ ProtoV5ProviderFactories : acctest .ProtoV5FactoriesAlternate (ctx , t ),
229
+ CheckDestroy : testAccCheckKeyDestroy (ctx ),
230
+ Steps : []resource.TestStep {
231
+ {
232
+ Config : testAccReplicaKeyConfig_multipleProviders (rName ),
233
+ Check : resource .ComposeTestCheckFunc (
234
+ testAccCheckKeyExists (ctx , resourceName , & key ),
235
+ acctest .MatchResourceAttrRegionalARN (ctx , resourceName , names .AttrARN , "kms" , regexache .MustCompile (`key/.+` )),
236
+ resource .TestCheckResourceAttr (resourceName , "bypass_policy_lockout_safety_check" , acctest .CtFalse ),
237
+ resource .TestCheckResourceAttr (resourceName , "deletion_window_in_days" , "30" ),
238
+ resource .TestCheckResourceAttr (resourceName , names .AttrDescription , "" ),
239
+ resource .TestCheckResourceAttr (resourceName , names .AttrEnabled , acctest .CtTrue ),
240
+ resource .TestCheckResourceAttr (resourceName , "key_rotation_enabled" , acctest .CtFalse ),
241
+ resource .TestCheckResourceAttr (resourceName , "key_spec" , "SYMMETRIC_DEFAULT" ),
242
+ resource .TestMatchResourceAttr (resourceName , names .AttrPolicy , regexache .MustCompile (`Enable IAM User Permissions` )),
243
+ resource .TestCheckResourceAttrPair (resourceName , "primary_key_arn" , primaryKeyResourceName , names .AttrARN ),
244
+ ),
245
+ ConfigStateChecks : []statecheck.StateCheck {
246
+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New (names .AttrTags ), knownvalue .Null ()),
247
+ statecheck .ExpectKnownValue (resourceName , tfjsonpath .New (names .AttrTagsAll ), knownvalue .MapExact (map [string ]knownvalue.Check {})),
248
+ },
249
+ },
250
+ {
251
+ ResourceName : resourceName ,
252
+ ImportState : true ,
253
+ ImportStateVerify : true ,
254
+ ImportStateVerifyIgnore : []string {"deletion_window_in_days" , "bypass_policy_lockout_safety_check" },
255
+ },
256
+ },
257
+ })
258
+ }
259
+
215
260
func testAccCheckReplicaKeyDestroy (ctx context.Context ) resource.TestCheckFunc {
216
261
return testAccCheckKeyDestroy (ctx )
217
262
}
@@ -221,9 +266,9 @@ func testAccCheckReplicaKeyExists(ctx context.Context, name string, key *awstype
221
266
}
222
267
223
268
func testAccReplicaKeyConfig_basic (rName string ) string {
224
- return acctest . ConfigCompose ( acctest . ConfigAlternateRegionProvider (), fmt .Sprintf (`
269
+ return fmt .Sprintf (`
225
270
resource "aws_kms_key" "test" {
226
- provider = awsalternate
271
+ region = %[2]q
227
272
228
273
description = %[1]q
229
274
multi_region = true
@@ -234,13 +279,13 @@ resource "aws_kms_key" "test" {
234
279
resource "aws_kms_replica_key" "test" {
235
280
primary_key_arn = aws_kms_key.test.arn
236
281
}
237
- ` , rName ))
282
+ ` , rName , acctest . AlternateRegion ( ))
238
283
}
239
284
240
285
func testAccReplicaKeyConfig_descriptionAndEnabled (rName , description string , enabled bool ) string {
241
- return acctest . ConfigCompose ( acctest . ConfigAlternateRegionProvider (), fmt .Sprintf (`
286
+ return fmt .Sprintf (`
242
287
resource "aws_kms_key" "test" {
243
- provider = awsalternate
288
+ region = %[4]q
244
289
245
290
description = %[1]q
246
291
multi_region = true
@@ -256,13 +301,13 @@ resource "aws_kms_replica_key" "test" {
256
301
257
302
deletion_window_in_days = 7
258
303
}
259
- ` , rName , description , enabled ))
304
+ ` , rName , description , enabled , acctest . AlternateRegion ( ))
260
305
}
261
306
262
307
func testAccReplicaKeyConfig_policy (rName , policy string , bypassLockoutCheck bool ) string {
263
- return acctest . ConfigCompose ( acctest . ConfigAlternateRegionProvider (), fmt .Sprintf (`
308
+ return fmt .Sprintf (`
264
309
resource "aws_kms_key" "test" {
265
- provider = awsalternate
310
+ region = %[4]q
266
311
267
312
description = %[1]q
268
313
multi_region = true
@@ -281,13 +326,13 @@ resource "aws_kms_replica_key" "test" {
281
326
282
327
policy = %[2]q
283
328
}
284
- ` , rName , policy , bypassLockoutCheck ))
329
+ ` , rName , policy , bypassLockoutCheck , acctest . AlternateRegion ( ))
285
330
}
286
331
287
332
func testAccReplicaKeyConfig_two (rName string ) string {
288
- return acctest . ConfigCompose ( acctest . ConfigMultipleRegionProvider ( 3 ), fmt .Sprintf (`
333
+ return fmt .Sprintf (`
289
334
resource "aws_kms_key" "test" {
290
- provider = awsalternate
335
+ region = %[2]q
291
336
292
337
description = %[1]q
293
338
multi_region = true
@@ -304,12 +349,27 @@ resource "aws_kms_replica_key" "test1" {
304
349
}
305
350
306
351
resource "aws_kms_replica_key" "test2" {
307
- provider = awsthird
352
+ region = %[3]q
308
353
309
354
description = %[1]q
310
355
primary_key_arn = aws_kms_key.test.arn
311
356
312
357
deletion_window_in_days = 7
313
358
}
359
+ ` , rName , acctest .AlternateRegion (), acctest .ThirdRegion ())
360
+ }
361
+
362
+ func testAccReplicaKeyConfig_multipleProviders (rName string ) string {
363
+ return acctest .ConfigCompose (acctest .ConfigAlternateRegionProvider (), fmt .Sprintf (`
364
+ resource "aws_kms_key" "test" {
365
+ provider = awsalternate
366
+
367
+ description = %[1]q
368
+ multi_region = true
369
+ }
370
+
371
+ resource "aws_kms_replica_key" "test" {
372
+ primary_key_arn = aws_kms_key.test.arn
373
+ }
314
374
` , rName ))
315
375
}
0 commit comments