From e95a34c6bb6053e7619618bf6a6a97ef7df0c80c Mon Sep 17 00:00:00 2001 From: Benjamin Bennett Date: Thu, 5 May 2022 16:46:56 +0100 Subject: [PATCH] Removing SDKv2 provider (#177) --- internal/provider/provider.go | 25 ------ internal/provider/provider_test.go | 30 ------- internal/provider/resource_shuffle.go | 113 -------------------------- internal/provider/seed.go | 24 ------ main.go | 2 - 5 files changed, 194 deletions(-) delete mode 100644 internal/provider/provider.go delete mode 100644 internal/provider/provider_test.go delete mode 100644 internal/provider/resource_shuffle.go delete mode 100644 internal/provider/seed.go diff --git a/internal/provider/provider.go b/internal/provider/provider.go deleted file mode 100644 index 8cda3537..00000000 --- a/internal/provider/provider.go +++ /dev/null @@ -1,25 +0,0 @@ -package provider - -import ( - "context" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) - -func init() { - schema.DescriptionKind = schema.StringMarkdown -} - -// New returns a *schema.Provider. -func New() *schema.Provider { - return &schema.Provider{ - Schema: map[string]*schema.Schema{}, - - ResourcesMap: map[string]*schema.Resource{}, - } -} - -func RemoveResourceFromState(_ context.Context, d *schema.ResourceData, _ interface{}) diag.Diagnostics { - d.SetId("") - return nil -} diff --git a/internal/provider/provider_test.go b/internal/provider/provider_test.go deleted file mode 100644 index bde42d24..00000000 --- a/internal/provider/provider_test.go +++ /dev/null @@ -1,30 +0,0 @@ -package provider - -import ( - "testing" - - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" -) - -var testAccProvider *schema.Provider -var testAccProviders map[string]func() (*schema.Provider, error) - -func init() { - testAccProvider = New() - testAccProviders = map[string]func() (*schema.Provider, error){ - "random": func() (*schema.Provider, error) { return testAccProvider, nil }, - } -} - -func TestProvider(t *testing.T) { - if err := New().InternalValidate(); err != nil { - t.Fatalf("err: %s", err) - } -} - -func TestProvider_impl(t *testing.T) { - var _ *schema.Provider = New() -} - -func testAccPreCheck(t *testing.T) { -} diff --git a/internal/provider/resource_shuffle.go b/internal/provider/resource_shuffle.go deleted file mode 100644 index ccf04932..00000000 --- a/internal/provider/resource_shuffle.go +++ /dev/null @@ -1,113 +0,0 @@ -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.", - CreateContext: CreateShuffle, - ReadContext: schema.NoopContext, - DeleteContext: RemoveResourceFromState, - - Schema: map[string]*schema.Schema{ - "keepers": { - Description: "Arbitrary map of values that, when changed, will trigger recreation of " + - "resource. See [the main provider documentation](../index.html) for more information.", - Type: schema.TypeMap, - Optional: true, - ForceNew: true, - }, - - "seed": { - Description: "Arbitrary string with which to seed the random number generator, in order to " + - "produce less-volatile permutations of the list.\n" + - "\n" + - "**Important:** Even with an identical seed, it is not guaranteed that the same permutation " + - "will be produced across different versions of Terraform. This argument causes the " + - "result to be *less volatile*, but not fixed for all time.", - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - - "input": { - Description: "The list of strings to shuffle.", - Type: schema.TypeList, - Required: true, - ForceNew: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - - "result_count": { - Description: "The number of results to return. Defaults to the number of items in the " + - "`input` list. If fewer items are requested, some elements will be excluded from the " + - "result. If more items are requested, items will be repeated in the result but not more " + - "frequently than the number of items in the input list.", - Type: schema.TypeInt, - Optional: true, - ForceNew: true, - }, - - "result": { - Description: "Random permutation of the list of strings given in `input`.", - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - - "id": { - Description: "A static value used internally by Terraform, this should not be referenced in configurations.", - Type: schema.TypeString, - Computed: true, - }, - }, - } -} - -func CreateShuffle(_ context.Context, d *schema.ResourceData, _ interface{}) diag.Diagnostics { - input := d.Get("input").([]interface{}) - seed := d.Get("seed").(string) - - resultCount := d.Get("result_count").(int) - if resultCount == 0 { - resultCount = len(input) - } - result := make([]interface{}, 0, resultCount) - - if len(input) > 0 { - rand := NewRand(seed) - - // Keep producing permutations until we fill our result - Batches: - for { - perm := rand.Perm(len(input)) - - for _, i := range perm { - result = append(result, input[i]) - - if len(result) >= resultCount { - break Batches - } - } - } - - } - - d.SetId("-") - - if err := d.Set("result", result); err != nil { - return diag.Errorf("error setting result: %s", err) - } - - return nil -} diff --git a/internal/provider/seed.go b/internal/provider/seed.go deleted file mode 100644 index 4d3c5265..00000000 --- a/internal/provider/seed.go +++ /dev/null @@ -1,24 +0,0 @@ -package provider - -import ( - "hash/crc64" - "math/rand" - "time" -) - -// NewRand returns a seeded random number generator, using a seed derived -// from the provided string. -// -// If the seed string is empty, the current time is used as a seed. -func NewRand(seed string) *rand.Rand { - var seedInt int64 - if seed != "" { - crcTable := crc64.MakeTable(crc64.ISO) - seedInt = int64(crc64.Checksum([]byte(seed), crcTable)) - } else { - seedInt = time.Now().UnixNano() - } - - randSource := rand.NewSource(seedInt) - return rand.New(randSource) -} diff --git a/main.go b/main.go index e1c2fa15..73a99c70 100644 --- a/main.go +++ b/main.go @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov6" "github.com/hashicorp/terraform-plugin-mux/tf5muxserver" "github.com/hashicorp/terraform-plugin-mux/tf6to5server" - "github.com/terraform-providers/terraform-provider-random/internal/provider" "github.com/terraform-providers/terraform-provider-random/internal/provider_fm" "log" ) @@ -37,7 +36,6 @@ func main() { func() tfprotov5.ProviderServer { return downgradedFrameworkProvider }, - provider.New().GRPCProvider, } muxServer, err := tf5muxserver.NewMuxServer(ctx, providers...)