From dff69f097aafbbf5a4179f8213bc1ba906f5e292 Mon Sep 17 00:00:00 2001 From: Noureddine Seddik Date: Tue, 27 Jul 2021 10:40:05 +0100 Subject: [PATCH] Resource schema references semantic, from "references" to singular "reference" property --- README.md | 4 +-- examples/main.tf | 2 +- schemaregistry/fixtures.go | 2 +- schemaregistry/resource_schema.go | 12 ++++----- schemaregistry/resource_schema_test.go | 34 +++++++++++++------------- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 8b301a0..e7cb216 100644 --- a/README.md +++ b/README.md @@ -49,14 +49,14 @@ resource "schemaregistry_schema" "with_reference" { subject = "with_reference_subject" schema = "[\"akc.test.event\", \"akc.test.other_event\"]" - references { + reference { name = "akc.test.event" subject = schemaregistry_schema.referenced_event.subject // version will always be upgraded with the referenced event schema version version = schemaregistry_schema.referenced_event.version } - references { + reference { name = "akc.test.other_event" subject = schemaregistry_schema.user_added.subject // version will always be upgraded with the referenced event schema version diff --git a/examples/main.tf b/examples/main.tf index 6d9de7b..3d10347 100644 --- a/examples/main.tf +++ b/examples/main.tf @@ -20,7 +20,7 @@ resource "schemaregistry_schema" "with_reference" { subject = "with-reference" schema = "[\"akc.test.userAdded\"]" - references { + reference { name = "akc.test.userAdded" subject = schemaregistry_schema.user_added.subject version = schemaregistry_schema.user_added.version diff --git a/schemaregistry/fixtures.go b/schemaregistry/fixtures.go index eedad81..f251f38 100644 --- a/schemaregistry/fixtures.go +++ b/schemaregistry/fixtures.go @@ -73,7 +73,7 @@ func fixtureResourceSchemaWithReferenceBuild(s schemaWithReferenceFixture) strin schema = "{{.WithReferences.Schema}}" {{range .References}} - references { + reference { name = "{{.Name}}" subject = {{.Subject}} version = {{.Version}} diff --git a/schemaregistry/resource_schema.go b/schemaregistry/resource_schema.go index c9c8b2b..3fe0515 100644 --- a/schemaregistry/resource_schema.go +++ b/schemaregistry/resource_schema.go @@ -57,7 +57,7 @@ func resourceSchema() *schema.Resource { Computed: true, Description: "The schema string", }, - "references": { + "reference": { Type: schema.TypeList, Optional: true, Description: "The referenced schema list", @@ -90,7 +90,7 @@ func schemaCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) subject := d.Get("subject").(string) schemaString := d.Get("schema").(string) - references := ToRegistryReferences(d.Get("references").([]interface{})) + references := ToRegistryReferences(d.Get("reference").([]interface{})) client := meta.(*srclient.SchemaRegistryClient) @@ -104,7 +104,7 @@ func schemaCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) d.Set("schema", schema.Schema()) d.Set("version", schema.Version()) - if err = d.Set("references", FromRegistryReferences(schema.References())); err != nil { + if err = d.Set("reference", FromRegistryReferences(schema.References())); err != nil { return diag.FromErr(err) } @@ -116,7 +116,7 @@ func schemaUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) subject := d.Get("subject").(string) schemaString := d.Get("schema").(string) - references := ToRegistryReferences(d.Get("references").([]interface{})) + references := ToRegistryReferences(d.Get("reference").([]interface{})) client := meta.(*srclient.SchemaRegistryClient) @@ -132,7 +132,7 @@ func schemaUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) d.Set("schema", schema.Schema()) d.Set("version", schema.Version()) - if err = d.Set("references", FromRegistryReferences(schema.References())); err != nil { + if err = d.Set("reference", FromRegistryReferences(schema.References())); err != nil { return diag.FromErr(err) } @@ -155,7 +155,7 @@ func schemaRead(ctx context.Context, d *schema.ResourceData, meta interface{}) d d.Set("subject", subject) d.Set("version", schema.Version()) - if err = d.Set("references", FromRegistryReferences(schema.References())); err != nil { + if err = d.Set("reference", FromRegistryReferences(schema.References())); err != nil { return diag.FromErr(err) } diff --git a/schemaregistry/resource_schema_test.go b/schemaregistry/resource_schema_test.go index acbc56a..53a3a42 100644 --- a/schemaregistry/resource_schema_test.go +++ b/schemaregistry/resource_schema_test.go @@ -168,10 +168,10 @@ func TestAccResourceSchemaReferences_basic(t *testing.T) { resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "version", "1"), resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "schema", strings.Replace(`[\"akc.test.userAdded\"]`, "\\", "", -1)), - resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "references.#", "1"), - resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "references.0.name", "akc.test.userAdded"), - resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "references.0.subject", fmt.Sprintf("referencedSub-%s", u)), - resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "references.0.version", "1"), + resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "reference.#", "1"), + resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "reference.0.name", "akc.test.userAdded"), + resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "reference.0.subject", fmt.Sprintf("referencedSub-%s", u)), + resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "reference.0.version", "1"), }, }, { @@ -226,15 +226,15 @@ func TestAccResourceSchemaReferences_basic(t *testing.T) { resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "version", "1"), resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "schema", strings.Replace(`[\"akc.test.userAdded\"]`, "\\", "", -1)), - resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "references.#", "2"), + resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "reference.#", "2"), - resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "references.0.name", "akc.test.userAdded"), - resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "references.0.subject", fmt.Sprintf("referencedSub-%s", u)), - resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "references.0.version", "1"), + resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "reference.0.name", "akc.test.userAdded"), + resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "reference.0.subject", fmt.Sprintf("referencedSub-%s", u)), + resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "reference.0.version", "1"), - resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "references.1.name", "foo.bar.other"), - resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "references.1.subject", fmt.Sprintf("otherReferencedSub-%s", u)), - resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "references.1.version", "1"), + resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "reference.1.name", "foo.bar.other"), + resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "reference.1.subject", fmt.Sprintf("otherReferencedSub-%s", u)), + resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "reference.1.version", "1"), }, }, } @@ -341,8 +341,8 @@ func TestAccResourceSchemaReferences_updateCompatible(t *testing.T) { resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "id", schemaWithReferenceSubject), resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "version", "1"), - resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "references.#", "1"), - resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "references.0.version", "1"), + resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "reference.#", "1"), + resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "reference.0.version", "1"), ), }, { @@ -374,8 +374,8 @@ func TestAccResourceSchemaReferences_updateCompatible(t *testing.T) { resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "id", schemaWithReferenceSubject), resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "version", "2"), - resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "references.#", "1"), - resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "references.0.version", "2"), + resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "reference.#", "1"), + resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "reference.0.version", "2"), ), }, }, @@ -424,8 +424,8 @@ func TestAccResourceSchemaReferences_updateIncompatible(t *testing.T) { resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "id", schemaWithReferenceSubject), resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "version", "1"), - resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "references.#", "1"), - resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "references.0.version", "1"), + resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "reference.#", "1"), + resource.TestCheckResourceAttr("schemaregistry_schema.schemaWithReference", "reference.0.version", "1"), ), }, {