Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(aws_schemas_schema): add JSON Schema support #33442

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/35971.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/aws_schemas_schema: Add `JSONSchemaDraft4` schema type support
```
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ require (
github.com/aws/aws-sdk-go-v2/service/s3 v1.38.5
github.com/aws/aws-sdk-go-v2/service/s3control v1.33.0
github.com/aws/aws-sdk-go-v2/service/scheduler v1.2.5
github.com/aws/aws-sdk-go-v2/service/schemas v1.16.6
github.com/aws/aws-sdk-go-v2/service/securitylake v1.7.0
github.com/aws/aws-sdk-go-v2/service/sesv2 v1.20.0
github.com/aws/aws-sdk-go-v2/service/signer v1.16.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ github.com/aws/aws-sdk-go-v2/service/s3control v1.33.0 h1:f4qHghGTcns4L4F7u8AHH6
github.com/aws/aws-sdk-go-v2/service/s3control v1.33.0/go.mod h1:YSdqo9knBVm5H3JVmWDhx9Wts9828nColUJzL3OKXDk=
github.com/aws/aws-sdk-go-v2/service/scheduler v1.2.5 h1:AGRPn7Hef59Eb9zfXjf6MGn0xRPpO73dIV8u8pfo5Z8=
github.com/aws/aws-sdk-go-v2/service/scheduler v1.2.5/go.mod h1:cdpHC7Nd4Yvtf/rhRqyqqI0fzoCb0fpo2oOFVZ0HTeQ=
github.com/aws/aws-sdk-go-v2/service/schemas v1.16.6 h1:Sqx33Tr3OBbMpuvj1zmltG1iXbHIZkZmuGkKNSMTi+Q=
github.com/aws/aws-sdk-go-v2/service/schemas v1.16.6/go.mod h1:IJI1++/Kjsjg6R3ZjOkR+MtW6TP1j1pU7CffPQDRNVQ=
github.com/aws/aws-sdk-go-v2/service/securitylake v1.7.0 h1:Ou2rjk3siybv09bzpi5fs+9zOYZACxT1LT0KkcDAtIs=
github.com/aws/aws-sdk-go-v2/service/securitylake v1.7.0/go.mod h1:/MCawoN8Xib5q04k2HsIQ+K2cNtC3CHamrfLZXd6KmA=
github.com/aws/aws-sdk-go-v2/service/sesv2 v1.20.0 h1:BVjuGDN2ek2gjSB46aIODXIYq3Aw/o0F/ZwBPP883GU=
Expand Down
10 changes: 9 additions & 1 deletion internal/service/schemas/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/YakDriver/regexache"
"github.com/aws/aws-sdk-go-v2/service/schemas/types"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/schemas"
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
Expand Down Expand Up @@ -77,7 +78,7 @@ func ResourceSchema() *schema.Resource {
"type": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(schemas.Type_Values(), true),
ValidateFunc: validation.StringInSlice(schemaTypes(), true),
},

"version": {
Expand Down Expand Up @@ -234,3 +235,10 @@ func resourceSchemaDelete(ctx context.Context, d *schema.ResourceData, meta inte

return diags
}

func schemaTypes() []string {
return []string{
string(types.TypeOpenApi3),
string(types.TypeJSONSchemaDraft4),
}
}
80 changes: 77 additions & 3 deletions internal/service/schemas/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,36 @@ const (
"format": "date-time"
}
}
}
}
}
}
}
}
`

testAccJSONSchemaContent = `
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/product.schema.json",
"title": "Event",
"description": "An generic example",
"type": "object",
"properties": {
"name": {
"description": "The unique identifier for a product",
"type": "string"
},
"created_at": {
"description": "Date-time format",
"type": "string",
"format": "date-time"
}
},
"required": [ "name" ]
}
`
)

func TestAccSchemasSchema_basic(t *testing.T) {
func TestAccSchemasSchema_openAPI3(t *testing.T) {
ctx := acctest.Context(t)
var v schemas.DescribeSchemaOutput
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
Expand Down Expand Up @@ -107,6 +129,43 @@ func TestAccSchemasSchema_basic(t *testing.T) {
})
}

func TestAccSchemasSchema_jsonSchemaDraftv4(t *testing.T) {
ctx := acctest.Context(t)
var v schemas.DescribeSchemaOutput
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
resourceName := "aws_schemas_schema.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckPartitionHasService(t, schemas.EndpointsID) },
ErrorCheck: acctest.ErrorCheck(t, schemas.EndpointsID),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
CheckDestroy: testAccCheckSchemaDestroy(ctx),
Steps: []resource.TestStep{
{
Config: testAccSchemaConfig_jsonSchema(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckSchemaExists(ctx, resourceName, &v),
acctest.CheckResourceAttrRegionalARN(resourceName, "arn", "schemas", fmt.Sprintf("schema/%s/%s", rName, rName)),
resource.TestCheckResourceAttr(resourceName, "description", ""),
resource.TestCheckResourceAttr(resourceName, "content", testAccJSONSchemaContent),
resource.TestCheckResourceAttrSet(resourceName, "last_modified"),
resource.TestCheckResourceAttr(resourceName, "name", rName),
resource.TestCheckResourceAttr(resourceName, "registry_name", rName),
resource.TestCheckResourceAttr(resourceName, "type", "JSONSchemaDraft4"),
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
resource.TestCheckResourceAttr(resourceName, "version", "1"),
resource.TestCheckResourceAttrSet(resourceName, "version_created_date"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func TestAccSchemasSchema_disappears(t *testing.T) {
ctx := acctest.Context(t)
var v schemas.DescribeSchemaOutput
Expand Down Expand Up @@ -302,6 +361,21 @@ resource "aws_schemas_schema" "test" {
`, rName, testAccSchemaContent)
}

func testAccSchemaConfig_jsonSchema(rName string) string {
return fmt.Sprintf(`
resource "aws_schemas_registry" "test" {
name = %[1]q
}

resource "aws_schemas_schema" "test" {
name = %[1]q
registry_name = aws_schemas_registry.test.name
type = "JSONSchemaDraft4"
content = %[2]q
}
`, rName, testAccJSONSchemaContent)
}

func testAccSchemaConfig_contentDescription(rName, content, description string) string {
return fmt.Sprintf(`
resource "aws_schemas_registry" "test" {
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/schemas_schema.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ This resource supports the following arguments:
* `name` - (Required) The name of the schema. Maximum of 385 characters consisting of lower case letters, upper case letters, ., -, _, @.
* `content` - (Required) The schema specification. Must be a valid Open API 3.0 spec.
* `registry_name` - (Required) The name of the registry in which this schema belongs.
* `type` - (Required) The type of the schema. Valid values: `OpenApi3`.
* `type` - (Required) The type of the schema. Valid values: `OpenApi3` or `JSONSchemaDraft4`.
* `description` - (Optional) The description of the schema. Maximum of 256 characters.
* `tags` - (Optional) A map of tags to assign to the resource. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.

Expand Down