Skip to content

Commit

Permalink
Merge pull request #19 from Kekenika/add-missing-read
Browse files Browse the repository at this point in the history
Add `read` for every `create` or `update`
  • Loading branch information
KeisukeYamashita authored Jan 28, 2022
2 parents 32fbc60 + 006a012 commit f2d6334
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 18 deletions.
8 changes: 2 additions & 6 deletions typesense/resource_collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ func resourceTypesenseCollection() *schema.Resource {
func resourceTypesenseCollectionCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*typesense.Client)

var diags diag.Diagnostics

schema := &api.CollectionSchema{}

if v := d.Get("name"); v != "" {
Expand Down Expand Up @@ -141,7 +139,7 @@ func resourceTypesenseCollectionCreate(ctx context.Context, d *schema.ResourceDa
}

d.SetId(collection.Name)
return diags
return resourceTypesenseCollectionRead(ctx, d, meta)
}

func resourceTypesenseCollectionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
Expand Down Expand Up @@ -183,8 +181,6 @@ func resourceTypesenseCollectionRead(ctx context.Context, d *schema.ResourceData
func resourceTypesenseCollectionUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*typesense.Client)

var diags diag.Diagnostics

id := d.Id()

_, err := client.Collection(id).Delete()
Expand Down Expand Up @@ -235,7 +231,7 @@ func resourceTypesenseCollectionUpdate(ctx context.Context, d *schema.ResourceDa
return diag.FromErr(err)
}

return diags
return resourceTypesenseCurationRead(ctx, d, meta)
}

func resourceTypesenseCollectionDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
Expand Down
4 changes: 1 addition & 3 deletions typesense/resource_collection_alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ func resourceTypesenseCollectionAlias() *schema.Resource {
func resourceTypesenseCollectionAliasUpsert(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*typesense.Client)

var diags diag.Diagnostics

name := d.Get("name").(string)
aliasSchema := &api.CollectionAliasSchema{
CollectionName: d.Get("collection_name").(string),
Expand All @@ -51,7 +49,7 @@ func resourceTypesenseCollectionAliasUpsert(ctx context.Context, d *schema.Resou
}

d.SetId(alias.Name)
return diags
return resourceTypesenseCollectionAliasRead(ctx, d, meta)
}

func resourceTypesenseCollectionAliasRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
Expand Down
4 changes: 1 addition & 3 deletions typesense/resource_curation.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ func resourceTypesenseCuration() *schema.Resource {
func resourceTypesenseCurationUpsert(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*typesense.Client)

var diags diag.Diagnostics

name := d.Get("name").(string)
collectionName := d.Get("collection_name").(string)
overwriteSchema := &api.SearchOverrideSchema{}
Expand Down Expand Up @@ -147,7 +145,7 @@ func resourceTypesenseCurationUpsert(ctx context.Context, d *schema.ResourceData
}

d.SetId(fmt.Sprintf("%s.%s", collectionName, override.Id))
return diags
return resourceTypesenseCurationRead(ctx, d, meta)
}

func resourceTypesenseCurationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
Expand Down
4 changes: 1 addition & 3 deletions typesense/resource_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ func resourceTypesenseDocument() *schema.Resource {
func resourceTypesenseDocumentUpsert(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*typesense.Client)

var diags diag.Diagnostics

var collectionName string

if v, ok := d.GetOk("collection_name"); ok {
Expand All @@ -68,7 +66,7 @@ func resourceTypesenseDocumentUpsert(ctx context.Context, d *schema.ResourceData
}

d.SetId(fmt.Sprintf("%s.%s", collectionName, id))
return diags
return resourceTypesenseCurationRead(ctx, d, meta)
}

func resourceTypesenseDocumentRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
Expand Down
4 changes: 1 addition & 3 deletions typesense/resource_synonyms.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ func resourceTypesenseSynonyms() *schema.Resource {
func resourceTypesenseSynonymsUpsert(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
client := meta.(*typesense.Client)

var diags diag.Diagnostics

name := d.Get("name").(string)
collectionName := d.Get("collection_name").(string)
synonymSchema := &api.SearchSynonymSchema{
Expand All @@ -70,7 +68,7 @@ func resourceTypesenseSynonymsUpsert(ctx context.Context, d *schema.ResourceData
}

d.SetId(fmt.Sprintf("%s.%s", collectionName, synonym.Id))
return diags
return resourceTypesenseCurationRead(ctx, d, meta)
}

func resourceTypesenseSynonymsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
Expand Down

0 comments on commit f2d6334

Please sign in to comment.