Skip to content

Commit

Permalink
Add aws_opensearchserverless_security_policy data source
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Luo committed Jun 28, 2023
1 parent 322977a commit 304e3fb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .changelog/32226.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-data-source
aws_opensearchserverless_security_policy
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ package opensearchserverless

import (
"context"
"regexp"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/opensearchserverless/types"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/enum"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
)

Expand All @@ -27,6 +31,10 @@ func DataSourceSecurityPolicy() *schema.Resource {
"name": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.All(
validation.StringLenBetween(3, 32),
validation.StringMatch(regexp.MustCompile(`^[a-z][a-z0-9-]+$`), `must start with any lower case letter and can include any lower case letter, number, or "-"`),
),
},
"policy": {
Type: schema.TypeString,
Expand All @@ -37,8 +45,9 @@ func DataSourceSecurityPolicy() *schema.Resource {
Computed: true,
},
"type": {
Type: schema.TypeString,
Required: true,
Type: schema.TypeString,
Required: true,
ValidateDiagFunc: enum.Validate[types.SecurityPolicyType](),
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestAccOpenSearchServerlessSecurityPolicyDataSource_basic(t *testing.T) {
},
ErrorCheck: acctest.ErrorCheck(t, names.OpenSearchServerlessEndpointID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckSecurityPolicyDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccSecurityPolicyDataSourceConfig_basic(rName),
Expand All @@ -31,6 +32,7 @@ func TestAccOpenSearchServerlessSecurityPolicyDataSource_basic(t *testing.T) {
resource.TestCheckResourceAttrPair(dataSourceName, "type", resourceName, "type"),
resource.TestCheckResourceAttrPair(dataSourceName, "description", resourceName, "description"),
resource.TestCheckResourceAttrPair(dataSourceName, "policy", resourceName, "policy"),
resource.TestCheckResourceAttrPair(dataSourceName, "policy_version", resourceName, "policy_version"),
),
},
},
Expand All @@ -41,20 +43,20 @@ func testAccSecurityPolicyDataSourceConfig_basic(rName string) string {
collection := fmt.Sprintf("collection/%s", rName)
return fmt.Sprintf(`
resource "aws_opensearchserverless_security_policy" "test" {
name = %[1]q
type = "encryption"
description = %[1]q
policy = jsonencode({
"Rules" = [
{
"Resource" = [
%[2]q
],
"ResourceType" = "collection"
}
],
"AWSOwnedKey" = true
})
name = %[1]q
type = "encryption"
description = %[1]q
policy = jsonencode({
"Rules" = [
{
"Resource" = [
%[2]q
],
"ResourceType" = "collection"
}
],
"AWSOwnedKey" = true
})
}
data "aws_opensearchserverless_security_policy" "test" {
Expand Down

0 comments on commit 304e3fb

Please sign in to comment.