Skip to content

Commit

Permalink
r/aws_iam_policy(test): duplicate JSON keys
Browse files Browse the repository at this point in the history
  • Loading branch information
jar-b committed Sep 22, 2023
1 parent a1e1e16 commit eded292
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions internal/service/iam/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,24 @@ func TestAccIAMPolicy_diffs(t *testing.T) {
})
}

func TestAccIAMPolicy_policyDuplicateKeys(t *testing.T) {
ctx := acctest.Context(t)
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t) },
ErrorCheck: acctest.ErrorCheck(t, iam.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckPolicyDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccPolicyConfig_policyDuplicateKeys(rName),
ExpectError: regexache.MustCompile(`"policy" contains duplicate JSON keys: duplicate key "Statement.0.Condition.StringEquals"`),
},
},
})
}

func testAccCheckPolicyExists(ctx context.Context, n string, v *iam.Policy) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -616,3 +634,32 @@ resource "aws_iam_policy" "test" {
}
`, rName, tags)
}

func testAccPolicyConfig_policyDuplicateKeys(rName string) string {
return fmt.Sprintf(`
resource "aws_iam_policy" "test" {
name = %q
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:PutObject",
"Resource": "*",
"Condition": {
"StringEquals": {
"s3:prefix": ["one/", "two/"]
},
"StringEquals": {
"s3:versionid": "abc123"
}
}
}
]
}
EOF
}
`, rName)
}

0 comments on commit eded292

Please sign in to comment.