diff --git a/.changelog/35971.txt b/.changelog/35971.txt new file mode 100644 index 00000000000..abca4bb2645 --- /dev/null +++ b/.changelog/35971.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/aws_schemas_schema: Add `JSONSchemaDraft4` schema type support +``` diff --git a/internal/service/schemas/schema.go b/internal/service/schemas/schema.go index fd99232fbff..9370e4ec02e 100644 --- a/internal/service/schemas/schema.go +++ b/internal/service/schemas/schema.go @@ -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" @@ -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": { @@ -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") +} diff --git a/internal/service/schemas/schema_test.go b/internal/service/schemas/schema_test.go index 3dad536d424..2a384319a3b 100644 --- a/internal/service/schemas/schema_test.go +++ b/internal/service/schemas/schema_test.go @@ -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) @@ -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 @@ -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" { diff --git a/website/docs/r/schemas_schema.html.markdown b/website/docs/r/schemas_schema.html.markdown index f1921004120..338aece0393 100644 --- a/website/docs/r/schemas_schema.html.markdown +++ b/website/docs/r/schemas_schema.html.markdown @@ -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.