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 all commits
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
```
8 changes: 7 additions & 1 deletion internal/service/schemas/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
tfslices "github.com/hashicorp/terraform-provider-aws/internal/slices"
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
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(type_Values(), true),
},

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

return diags
}

func type_Values() []string {
// For some reason AWS SDK for Go v1 does not define a TypeJSONSchemaDraft4 constant.
return tfslices.AppendUnique(schemas.Type_Values(), "JSONSchemaDraft4")
}
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
Loading