@@ -54,6 +54,41 @@ func TestAccBackupVaultPolicy_basic(t *testing.T) {
54
54
})
55
55
}
56
56
57
+ func TestAccBackupVaultPolicy_eventual_consistency (t * testing.T ) {
58
+ ctx := acctest .Context (t )
59
+ var vault backup.GetBackupVaultAccessPolicyOutput
60
+ rName := sdkacctest .RandomWithPrefix (acctest .ResourcePrefix )
61
+ resourceName := "aws_backup_vault_policy.test"
62
+
63
+ resource .ParallelTest (t , resource.TestCase {
64
+ PreCheck : func () { acctest .PreCheck (ctx , t ); testAccPreCheck (ctx , t ) },
65
+ ErrorCheck : acctest .ErrorCheck (t , backup .EndpointsID ),
66
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories ,
67
+ CheckDestroy : testAccCheckVaultPolicyDestroy (ctx ),
68
+ Steps : []resource.TestStep {
69
+ {
70
+ Config : testAccVaultPolicyConfig_eventual_consistency (rName ),
71
+ Check : resource .ComposeTestCheckFunc (
72
+ testAccCheckVaultPolicyExists (ctx , resourceName , & vault ),
73
+ resource .TestMatchResourceAttr (resourceName , "policy" , regexache .MustCompile ("^{\" Id\" :\" default\" .+" ))),
74
+ },
75
+ {
76
+ ResourceName : resourceName ,
77
+ ImportState : true ,
78
+ ImportStateVerify : true ,
79
+ },
80
+ {
81
+ Config : testAccVaultPolicyConfig_updated (rName ),
82
+ Check : resource .ComposeTestCheckFunc (
83
+ testAccCheckVaultPolicyExists (ctx , resourceName , & vault ),
84
+ resource .TestMatchResourceAttr (resourceName , "policy" , regexache .MustCompile ("^{\" Id\" :\" default\" .+" )),
85
+ resource .TestMatchResourceAttr (resourceName , "policy" , regexache .MustCompile ("backup:ListRecoveryPointsByBackupVault" )),
86
+ ),
87
+ },
88
+ },
89
+ })
90
+ }
91
+
57
92
func TestAccBackupVaultPolicy_disappears (t * testing.T ) {
58
93
ctx := acctest .Context (t )
59
94
var vault backup.GetBackupVaultAccessPolicyOutput
@@ -285,3 +320,33 @@ resource "aws_backup_vault_policy" "test" {
285
320
}
286
321
` , rName )
287
322
}
323
+
324
+ func testAccVaultPolicyConfig_eventual_consistency (rName string ) string {
325
+ return acctest .ConfigCompose (
326
+ testAccVaultPolicyConfig_basic (rName ),
327
+ fmt .Sprintf (`
328
+ data "aws_partition" "current" {}
329
+
330
+ resource "aws_iam_role" "test" {
331
+ name = %[1]q
332
+ assume_role_policy = jsonencode({
333
+ Version = "2012-10-17"
334
+ Statement = [
335
+ {
336
+ Action = "sts:AssumeRole"
337
+ Effect = "Allow"
338
+ Sid = ""
339
+ Principal = {
340
+ Service = "backup.amazonaws.com"
341
+ }
342
+ },
343
+ ]
344
+ })
345
+ }
346
+
347
+ resource "aws_iam_role_policy_attachment" "test" {
348
+ role = aws_iam_role.test.name
349
+ policy_arn = "arn:${data.aws_partition.current.partition}:iam::${data.aws_partition.current.partition}:policy/service-role/AWSBackupServiceRolePolicyForBackup"
350
+ }
351
+ ` , rName ))
352
+ }
0 commit comments