Skip to content

Commit

Permalink
Refactoring (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
bendbennett committed Jun 27, 2022
1 parent d12f1ad commit f888917
Show file tree
Hide file tree
Showing 25 changed files with 854 additions and 950 deletions.
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
package provider
package diagnostics

import (
"fmt"

"github.com/hashicorp/terraform-plugin-framework/diag"
)

const retryMsg = "Retry the Terraform operation. If the error still occurs or happens regularly, please contact the provider developer with hardware and operating system information.\n\n"
const RetryMsg = "Retry the Terraform operation. If the error still occurs or happens regularly, please contact the provider developer with hardware and operating system information.\n\n"

func randomReadError(errMsg string) diag.Diagnostics {
func RandomReadError(errMsg string) diag.Diagnostics {
var diags diag.Diagnostics

diags.AddError(
"Random Read Error",
"While attempting to generate a random value for this resource, a read error was generated.\n\n"+
retryMsg+
RetryMsg+
fmt.Sprintf("Original Error: %s", errMsg),
)

return diags
}

func hashGenerationError(errMsg string) diag.Diagnostics {
func HashGenerationError(errMsg string) diag.Diagnostics {
var diags diag.Diagnostics

diags.AddError(
"Hash Generation Error",
"While attempting to generate a hash from of the password an error occurred.\n\n"+
"While attempting to generate a hash from the password an error occurred.\n\n"+
"Verify that the state contains a populated 'result' field, using 'terraform state show', and retry the operation\n\n"+
fmt.Sprintf("Original Error: %s", errMsg),
)
Expand Down
128 changes: 0 additions & 128 deletions internal/provider/models.go

This file was deleted.

39 changes: 24 additions & 15 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,43 @@ import (

"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
)

type provider struct {
}
"github.com/terraform-providers/terraform-provider-random/internal/resources/id"
"github.com/terraform-providers/terraform-provider-random/internal/resources/integer"
"github.com/terraform-providers/terraform-provider-random/internal/resources/password"
"github.com/terraform-providers/terraform-provider-random/internal/resources/pet"
"github.com/terraform-providers/terraform-provider-random/internal/resources/shuffle"
stringresource "github.com/terraform-providers/terraform-provider-random/internal/resources/string"
"github.com/terraform-providers/terraform-provider-random/internal/resources/uuid"
)

func NewFramework() tfsdk.Provider {
func NewProvider() tfsdk.Provider {
return &provider{}
}

func (p *provider) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) {
var _ tfsdk.Provider = (*provider)(nil)

type provider struct{}

func (p *provider) GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics) {
return tfsdk.Schema{}, nil
}

func (p *provider) Configure(ctx context.Context, req tfsdk.ConfigureProviderRequest, resp *tfsdk.ConfigureProviderResponse) {
func (p *provider) Configure(context.Context, tfsdk.ConfigureProviderRequest, *tfsdk.ConfigureProviderResponse) {
}

func (p *provider) GetResources(ctx context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) {
func (p *provider) GetResources(context.Context) (map[string]tfsdk.ResourceType, diag.Diagnostics) {
return map[string]tfsdk.ResourceType{
"random_id": resourceIDType{},
"random_integer": resourceIntegerType{},
"random_password": resourcePasswordType{},
"random_pet": resourcePetType{},
"random_shuffle": resourceShuffleType{},
"random_string": resourceStringType{},
"random_uuid": resourceUUIDType{},
"random_id": id.NewResourceType(),
"random_integer": integer.NewResourceType(),
"random_password": password.NewResourceType(),
"random_pet": pet.NewResourceType(),
"random_shuffle": shuffle.NewResourceType(),
"random_string": stringresource.NewResourceType(),
"random_uuid": uuid.NewResourceType(),
}, nil
}

func (p *provider) GetDataSources(ctx context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) {
func (p *provider) GetDataSources(context.Context) (map[string]tfsdk.DataSourceType, diag.Diagnostics) {
return map[string]tfsdk.DataSourceType{}, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

func TestAccResourceID(t *testing.T) {
resource.UnitTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories(),
Steps: []resource.TestStep{
{
Expand All @@ -33,7 +32,6 @@ func TestAccResourceID(t *testing.T) {

func TestAccResourceID_importWithPrefix(t *testing.T) {
resource.UnitTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories(),
Steps: []resource.TestStep{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
func TestAccResourceIntegerBasic(t *testing.T) {
t.Parallel()
resource.UnitTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories(),
Steps: []resource.TestStep{
{
Expand All @@ -36,7 +35,6 @@ func TestAccResourceIntegerBasic(t *testing.T) {
func TestAccResourceIntegerUpdate(t *testing.T) {
t.Parallel()
resource.UnitTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories(),
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -66,7 +64,6 @@ func TestAccResourceIntegerUpdate(t *testing.T) {
func TestAccResourceIntegerSeedless_to_seeded(t *testing.T) {
t.Parallel()
resource.UnitTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories(),
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -95,7 +92,6 @@ func TestAccResourceIntegerSeedless_to_seeded(t *testing.T) {
func TestAccResourceIntegerSeeded_to_seedless(t *testing.T) {
t.Parallel()
resource.UnitTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories(),
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -124,7 +120,6 @@ func TestAccResourceIntegerSeeded_to_seedless(t *testing.T) {
func TestAccResourceIntegerBig(t *testing.T) {
t.Parallel()
resource.UnitTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories(),
Steps: []resource.TestStep{
{
Expand Down

0 comments on commit f888917

Please sign in to comment.