Skip to content

Commit

Permalink
aws_opensearchserverless_access_policy: test for updates
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsonaj committed Jun 12, 2023
1 parent 32067b1 commit c5fdf8a
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions internal/service/opensearchserverless/access_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,42 @@ func TestAccOpenSearchServerlessAccessPolicy_basic(t *testing.T) {
})
}

func TestAccOpenSearchServerlessAccessPolicy_update(t *testing.T) {
ctx := acctest.Context(t)
var accesspolicy types.AccessPolicyDetail
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_opensearchserverless_access_policy.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acctest.PreCheck(ctx, t)
acctest.PreCheckPartitionHasService(t, names.OpenSearchServerlessEndpointID)
testAccPreCheck(ctx, t)
},
ErrorCheck: acctest.ErrorCheck(t, names.OpenSearchServerlessEndpointID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckAccessPolicyDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccAccessPolicyConfig_update(rName, "description"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAccessPolicyExists(ctx, resourceName, &accesspolicy),
resource.TestCheckResourceAttr(resourceName, "type", "data"),
resource.TestCheckResourceAttr(resourceName, "description", "description"),
),
},
{
Config: testAccAccessPolicyConfig_update(rName, "description updated"),
Check: resource.ComposeTestCheckFunc(
testAccCheckAccessPolicyExists(ctx, resourceName, &accesspolicy),
resource.TestCheckResourceAttr(resourceName, "type", "data"),
resource.TestCheckResourceAttr(resourceName, "description", "description updated"),
),
},
},
})
}

func TestAccOpenSearchServerlessAccessPolicy_disappears(t *testing.T) {
ctx := acctest.Context(t)

Expand Down Expand Up @@ -163,6 +199,7 @@ func testAccAccessPolicyConfig_basic(rName string) string {
return fmt.Sprintf(`
data "aws_caller_identity" "current" {}
data "aws_partition" "current" {}
resource "aws_opensearchserverless_access_policy" "test" {
name = %[1]q
type = "data"
Expand Down Expand Up @@ -191,3 +228,38 @@ resource "aws_opensearchserverless_access_policy" "test" {
}
`, rName)
}

func testAccAccessPolicyConfig_update(rName, description string) string {
return fmt.Sprintf(`
data "aws_caller_identity" "current" {}
data "aws_partition" "current" {}
resource "aws_opensearchserverless_access_policy" "test" {
name = %[1]q
type = "data"
description = %[2]q
policy = jsonencode([
{
"Rules" : [
{
"ResourceType" : "index",
"Resource" : [
"index/books/*"
],
"Permission" : [
"aoss:CreateIndex",
"aoss:ReadDocument",
"aoss:UpdateIndex",
"aoss:DeleteIndex",
"aoss:WriteDocument"
]
}
],
"Principal" : [
"arn:${data.aws_partition.current.partition}:iam::${data.aws_caller_identity.current.account_id}:user/admin"
]
}
])
}
`, rName, description)
}

0 comments on commit c5fdf8a

Please sign in to comment.