Skip to content

Commit

Permalink
Replace usage of Create, Read and Delete fields with CreateContext, R…
Browse files Browse the repository at this point in the history
…eadContext and DeleteContext in resource_shuffle (#230)
  • Loading branch information
bendbennett committed Apr 12, 2022
1 parent b47c746 commit 1d6b7b1
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions internal/provider/resource_shuffle.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package provider

import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func resourceShuffle() *schema.Resource {
return &schema.Resource{
Description: "The resource `random_shuffle` generates a random permutation of a list of strings " +
"given as an argument.",
Create: CreateShuffle,
Read: schema.Noop,
Delete: schema.RemoveFromState,
CreateContext: CreateShuffle,
ReadContext: schema.NoopContext,
DeleteContext: DeleteShuffle,

Schema: map[string]*schema.Schema{
"keepers": {
Expand Down Expand Up @@ -71,7 +73,7 @@ func resourceShuffle() *schema.Resource {
}
}

func CreateShuffle(d *schema.ResourceData, _ interface{}) error {
func CreateShuffle(_ context.Context, d *schema.ResourceData, _ interface{}) diag.Diagnostics {
input := d.Get("input").([]interface{})
seed := d.Get("seed").(string)

Expand Down Expand Up @@ -105,3 +107,8 @@ func CreateShuffle(d *schema.ResourceData, _ interface{}) error {

return nil
}

func DeleteShuffle(_ context.Context, d *schema.ResourceData, _ interface{}) diag.Diagnostics {
d.SetId("")
return nil
}

0 comments on commit 1d6b7b1

Please sign in to comment.