diff --git a/auth0/provider.go b/auth0/provider.go index 2a86615b..3dbf23a2 100644 --- a/auth0/provider.go +++ b/auth0/provider.go @@ -4,18 +4,17 @@ import ( "fmt" "os" - "github.com/alexkappa/terraform-provider-auth0/version" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/meta" - "gopkg.in/auth0.v5" "gopkg.in/auth0.v5/management" -) -var provider *schema.Provider + "github.com/alexkappa/terraform-provider-auth0/version" +) -func init() { - provider = &schema.Provider{ +// Provider returns a *schema.Provider. +func Provider() *schema.Provider { + provider := &schema.Provider{ Schema: map[string]*schema.Schema{ "domain": { Type: schema.TypeString, @@ -69,45 +68,39 @@ func init() { "auth0_action": newAction(), "auth0_trigger_binding": newTriggerBinding(), }, - ConfigureFunc: Configure, } -} - -func Provider() *schema.Provider { - return provider -} - -func Configure(data *schema.ResourceData) (interface{}, error) { - domain := data.Get("domain").(string) - id := data.Get("client_id").(string) - secret := data.Get("client_secret").(string) - debug := data.Get("debug").(bool) + provider.ConfigureFunc = ConfigureProvider(provider.TerraformVersion) - userAgent := fmt.Sprintf("Terraform-Provider-Auth0/%s (Go-Auth0-SDK/%s; Terraform-SDK/%s; Terraform/%s)", - Version(), - SDKVersion(), - TerraformSDKVersion(), - TerraformVersion()) - - return management.New(domain, - management.WithClientCredentials(id, secret), - management.WithDebug(debug), - management.WithUserAgent(userAgent)) + return provider } -func Version() string { - return version.ProviderVersion -} +// ConfigureProvider will configure the *schema.Provider so that *management.Management +// client is stored and passed into the subsequent resources as the meta parameter. +func ConfigureProvider(terraformVersion string) func(data *schema.ResourceData) (interface{}, error) { + return func(data *schema.ResourceData) (interface{}, error) { + domain := data.Get("domain").(string) + id := data.Get("client_id").(string) + secret := data.Get("client_secret").(string) + debug := data.Get("debug").(bool) -func SDKVersion() string { - return auth0.Version -} + providerVersion := version.ProviderVersion + sdkVersion := auth0.Version + terraformSDKVersion := meta.SDKVersionString() -func TerraformVersion() string { - return provider.TerraformVersion -} + userAgent := fmt.Sprintf( + "Terraform-Provider-Auth0/%s (Go-Auth0-SDK/%s; Terraform-SDK/%s; Terraform/%s)", + providerVersion, + sdkVersion, + terraformSDKVersion, + terraformVersion, + ) -func TerraformSDKVersion() string { - return meta.SDKVersionString() + return management.New( + domain, + management.WithClientCredentials(id, secret), + management.WithDebug(debug), + management.WithUserAgent(userAgent), + ) + } } diff --git a/auth0/provider_test.go b/auth0/provider_test.go index 956620f3..1e154e6f 100644 --- a/auth0/provider_test.go +++ b/auth0/provider_test.go @@ -11,41 +11,18 @@ import ( "gopkg.in/auth0.v5/management" ) -func providerWithWiremock() *schema.Provider { - return &schema.Provider{ - ResourcesMap: map[string]*schema.Resource{ - "auth0_client": newClient(), - "auth0_global_client": newGlobalClient(), - "auth0_client_grant": newClientGrant(), - "auth0_connection": newConnection(), - "auth0_custom_domain": newCustomDomain(), - "auth0_custom_domain_verification": newCustomDomainVerification(), - "auth0_resource_server": newResourceServer(), - "auth0_rule": newRule(), - "auth0_rule_config": newRuleConfig(), - "auth0_hook": newHook(), - "auth0_prompt": newPrompt(), - "auth0_prompt_custom_text": newPromptCustomText(), - "auth0_email": newEmail(), - "auth0_email_template": newEmailTemplate(), - "auth0_user": newUser(), - "auth0_tenant": newTenant(), - "auth0_role": newRole(), - "auth0_log_stream": newLogStream(), - "auth0_branding": newBranding(), - "auth0_guardian": newGuardian(), - "auth0_organization": newOrganization(), - "auth0_action": newAction(), - "auth0_trigger_binding": newTriggerBinding(), - }, - ConfigureFunc: func(data *schema.ResourceData) (interface{}, error) { - return management.New( - "localhost:8080", - management.WithInsecure(), - management.WithDebug(true), - ) - }, +const wiremockHost = "localhost:8080" + +func providerWithTestingConfiguration() *schema.Provider { + provider := Provider() + provider.ConfigureFunc = func(data *schema.ResourceData) (interface{}, error) { + return management.New( + wiremockHost, + management.WithInsecure(), + management.WithDebug(true), + ) } + return provider } func Auth0() (*management.Management, error) { diff --git a/auth0/resource_auth0_custom_domain_verification_test.go b/auth0/resource_auth0_custom_domain_verification_test.go index d0f29e6a..2e12b74b 100644 --- a/auth0/resource_auth0_custom_domain_verification_test.go +++ b/auth0/resource_auth0_custom_domain_verification_test.go @@ -10,7 +10,7 @@ import ( func TestAccCustomDomainVerification(t *testing.T) { resource.Test(t, resource.TestCase{ Providers: map[string]terraform.ResourceProvider{ - "auth0": providerWithWiremock(), + "auth0": providerWithTestingConfiguration(), }, Steps: []resource.TestStep{ {