Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2/3] [DXCDT-54] Upgrade terraform-plugin-sdk to v2 #122

Merged
merged 14 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion auth0/data_source_auth0_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/auth0/go-auth0"
"github.com/auth0/go-auth0/management"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func newDataClient() *schema.Resource {
Expand Down
8 changes: 4 additions & 4 deletions auth0/data_source_auth0_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/auth0/terraform-provider-auth0/auth0/internal/random"
)
Expand All @@ -28,7 +28,7 @@ func TestAccDataClientByName(t *testing.T) {
rand := random.String(6)

resource.Test(t, resource.TestCase{
Providers: map[string]terraform.ResourceProvider{
Providers: map[string]*schema.Provider{
"auth0": Provider(),
},
PreventPostDestroyRefresh: true,
Expand Down Expand Up @@ -57,7 +57,7 @@ func TestAccDataClientById(t *testing.T) {
rand := random.String(6)

resource.Test(t, resource.TestCase{
Providers: map[string]terraform.ResourceProvider{
Providers: map[string]*schema.Provider{
"auth0": Provider(),
},
PreventPostDestroyRefresh: true,
Expand Down
2 changes: 1 addition & 1 deletion auth0/data_source_auth0_global_client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package auth0

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

func newDataGlobalClient() *schema.Resource {
Expand Down
6 changes: 3 additions & 3 deletions auth0/data_source_auth0_global_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

const testAccDataGlobalClientConfig = `
Expand All @@ -16,7 +16,7 @@ data auth0_global_client global {

func TestAccDataGlobalClient(t *testing.T) {
resource.Test(t, resource.TestCase{
Providers: map[string]terraform.ResourceProvider{
Providers: map[string]*schema.Provider{
"auth0": Provider(),
},
Steps: []resource.TestStep{
Expand Down
4 changes: 2 additions & 2 deletions auth0/data_source_auth0_tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"github.com/auth0/go-auth0/management"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func newDataTenant() *schema.Resource {
Expand Down
7 changes: 4 additions & 3 deletions auth0/data_source_auth0_tenant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/auth0/terraform-provider-auth0/auth0/internal/random"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

const testAccDataTenantConfig = `
Expand All @@ -30,7 +31,7 @@ func TestAccDataTenant(t *testing.T) {
rand := random.String(6)

resource.Test(t, resource.TestCase{
Providers: map[string]terraform.ResourceProvider{
Providers: map[string]*schema.Provider{
"auth0": Provider(),
},
Steps: []resource.TestStep{
Expand Down
2 changes: 1 addition & 1 deletion auth0/data_source_helpers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package auth0

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

// datasourceSchemaFromResourceSchema is a recursive func that
Expand Down
2 changes: 1 addition & 1 deletion auth0/data_source_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package auth0
import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

var newMockResourceSchema = map[string]*schema.Schema{
Expand Down
2 changes: 1 addition & 1 deletion auth0/internal/hash/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package hash
import (
"hash/crc32"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

// StringKey returns a schema.SchemaSetFunc able to hash a string value
Expand Down
4 changes: 2 additions & 2 deletions auth0/internal/random/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"bytes"
"text/template"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

// String generates a random alphanumeric string of the length specified.
Expand Down
4 changes: 2 additions & 2 deletions auth0/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"github.com/auth0/go-auth0"
"github.com/auth0/go-auth0/management"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/meta"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/meta"

"github.com/auth0/terraform-provider-auth0/version"
)
Expand Down
88 changes: 62 additions & 26 deletions auth0/provider_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package auth0

import (
"errors"
"context"
"fmt"
"os"
"sort"
"strings"
"testing"

"github.com/auth0/go-auth0/management"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

const wiremockHost = "localhost:8080"
Expand All @@ -28,12 +30,14 @@ func providerWithTestingConfiguration() *schema.Provider {
}

func Auth0() (*management.Management, error) {
c := terraform.NewResourceConfigRaw(nil)
p := Provider()
if err := p.Configure(c); err != nil {
return nil, err
config := terraform.NewResourceConfigRaw(nil)
provider := Provider()

if result := provider.Configure(context.Background(), config); result.HasError() {
return nil, fmt.Errorf("failed to configure provider")
}
return p.Meta().(*management.Management), nil

return provider.Meta().(*management.Management), nil
}

func TestMain(m *testing.M) {
Expand Down Expand Up @@ -78,26 +82,48 @@ func TestProvider_configValidation(t *testing.T) {
testCases := []struct {
name string
resourceConfig map[string]interface{}
expectedErrors []error
expectedErrors diag.Diagnostics
}{
{
name: "missing client id",
resourceConfig: map[string]interface{}{"domain": "test", "client_secret": "test"},
expectedErrors: []error{errors.New("\"client_secret\": all of `client_id,client_secret` must be specified")},
expectedErrors: diag.Diagnostics{
diag.Diagnostic{
Summary: "RequiredWith",
Detail: "\"client_secret\": all of `client_id,client_secret` must be specified",
},
},
},
{
name: "missing client secret",
resourceConfig: map[string]interface{}{"domain": "test", "client_id": "test"},
expectedErrors: []error{errors.New("\"client_id\": all of `client_id,client_secret` must be specified")},
expectedErrors: diag.Diagnostics{
diag.Diagnostic{
Summary: "RequiredWith",
Detail: "\"client_id\": all of `client_id,client_secret` must be specified",
},
},
},
{
name: "conflicting auth0 client and management token without domain",
resourceConfig: map[string]interface{}{"client_id": "test", "client_secret": "test", "api_token": "test"},
expectedErrors: []error{
errors.New("\"domain\": required field is not set"),
errors.New("\"client_id\": conflicts with api_token"),
errors.New("\"client_secret\": conflicts with api_token"),
errors.New("\"api_token\": conflicts with client_id"),
expectedErrors: diag.Diagnostics{
diag.Diagnostic{
Summary: "Missing required argument",
Detail: "The argument \"domain\" is required, but no definition was found.",
},
diag.Diagnostic{
Summary: "ConflictsWith",
Detail: "\"api_token\": conflicts with client_id",
},
diag.Diagnostic{
Summary: "ConflictsWith",
Detail: "\"client_id\": conflicts with api_token",
},
diag.Diagnostic{
Summary: "ConflictsWith",
Detail: "\"client_secret\": conflicts with api_token",
},
},
},
{
Expand All @@ -116,10 +142,10 @@ func TestProvider_configValidation(t *testing.T) {
os.Clearenv()
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
c := terraform.NewResourceConfigRaw(test.resourceConfig)
p := Provider()
config := terraform.NewResourceConfigRaw(test.resourceConfig)
provider := Provider()

_, errs := p.Validate(c)
errs := provider.Validate(config)
assertErrorsSliceEqual(t, test.expectedErrors, errs)
})
}
Expand All @@ -130,23 +156,33 @@ func TestProvider_configValidation(t *testing.T) {
}
}

func sortErrors(errs []error) {
func sortErrors(errs diag.Diagnostics) {
sort.Slice(errs, func(i, j int) bool {
return errs[i].Error() < errs[j].Error()
return errs[i].Detail < errs[j].Detail
})
}

func assertErrorsSliceEqual(t *testing.T, expected, actual []error) {
func assertErrorsSliceEqual(t *testing.T, expected, actual diag.Diagnostics) {
if len(expected) != len(actual) {
t.Fatalf("actual did not match expected. len(expected) != len(actual). expected: %v, actual: %v", expected, actual)
t.Fatalf(
"actual did not match expected. len(expected) != len(actual). expected: %v, actual: %v",
expected,
actual,
)
}

sortErrors(expected)
sortErrors(actual)

for i := range expected {
if expected[i].Error() != actual[i].Error() {
t.Fatalf("actual did not match expected. expected[%d] != actual[%d]. expected: %v, actual: %v", i, i, expected, actual)
if expected[i].Detail != actual[i].Detail {
t.Fatalf(
"actual did not match expected. expected[%d] != actual[%d]. expected: %+v, actual: %+v",
i,
i,
expected,
actual,
)
}
}
}
6 changes: 3 additions & 3 deletions auth0/resource_auth0_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (

"github.com/auth0/go-auth0/management"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

"github.com/auth0/terraform-provider-auth0/auth0/internal/hash"
)
Expand Down
8 changes: 4 additions & 4 deletions auth0/resource_auth0_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/auth0/terraform-provider-auth0/auth0/internal/random"
)
Expand All @@ -15,7 +15,7 @@ func TestAccAction(t *testing.T) {
rand := random.String(6)

resource.Test(t, resource.TestCase{
Providers: map[string]terraform.ResourceProvider{
Providers: map[string]*schema.Provider{
"auth0": Provider(),
},
Steps: []resource.TestStep{
Expand Down Expand Up @@ -52,7 +52,7 @@ func TestAccAction_FailedBuild(t *testing.T) {
rand := random.String(6)

resource.Test(t, resource.TestCase{
Providers: map[string]terraform.ResourceProvider{
Providers: map[string]*schema.Provider{
"auth0": Provider(),
},
Steps: []resource.TestStep{
Expand Down
6 changes: 3 additions & 3 deletions auth0/resource_auth0_attack_protection.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"net/http"

"github.com/auth0/go-auth0/management"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

func newAttackProtection() *schema.Resource {
Expand Down
6 changes: 3 additions & 3 deletions auth0/resource_auth0_attack_protection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ package auth0
import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func TestAccAttackProtection(t *testing.T) {
resource.Test(t, resource.TestCase{
Providers: map[string]terraform.ResourceProvider{
Providers: map[string]*schema.Provider{
"auth0": Provider(),
},
Steps: []resource.TestStep{
Expand Down
4 changes: 2 additions & 2 deletions auth0/resource_auth0_branding.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (

"github.com/auth0/go-auth0/management"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func newBranding() *schema.Resource {
Expand Down
Loading