diff --git a/internal/config/config.go b/internal/config/config.go index 372f19ce..7ccf9074 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -22,6 +22,8 @@ import ( ) const providerName = "Terraform-Provider-Auth0" // #nosec G101 +// MissingEnvVar is used as a default value for EnvDefaultFunc for var lookups that have no value. +const MissingEnvVar = "MISSING" var version = "dev" @@ -62,7 +64,7 @@ func ConfigureProvider(terraformVersion *string) schema.ConfigureContextFunc { audience := data.Get("audience").(string) debug := data.Get("debug").(bool) - if apiToken == "" && (clientID == "" || clientSecret == "" || domain == "") { + if apiToken == MissingEnvVar && (clientID == MissingEnvVar || clientSecret == MissingEnvVar || domain == MissingEnvVar) { return nil, diag.Diagnostics{ { Severity: diag.Error, diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 7369bb9b..a6c9ed15 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -41,7 +41,7 @@ func New() *schema.Provider { "domain": { Type: schema.TypeString, Optional: true, - DefaultFunc: schema.EnvDefaultFunc("AUTH0_DOMAIN", nil), + DefaultFunc: schema.EnvDefaultFunc("AUTH0_DOMAIN", config.MissingEnvVar), Description: "Your Auth0 domain name. " + "It can also be sourced from the `AUTH0_DOMAIN` environment variable.", }, @@ -55,7 +55,7 @@ func New() *schema.Provider { "client_id": { Type: schema.TypeString, Optional: true, - DefaultFunc: schema.EnvDefaultFunc("AUTH0_CLIENT_ID", nil), + DefaultFunc: schema.EnvDefaultFunc("AUTH0_CLIENT_ID", config.MissingEnvVar), RequiredWith: []string{"client_secret"}, ConflictsWith: []string{"api_token"}, Description: "Your Auth0 client ID. " + @@ -64,7 +64,7 @@ func New() *schema.Provider { "client_secret": { Type: schema.TypeString, Optional: true, - DefaultFunc: schema.EnvDefaultFunc("AUTH0_CLIENT_SECRET", nil), + DefaultFunc: schema.EnvDefaultFunc("AUTH0_CLIENT_SECRET", config.MissingEnvVar), RequiredWith: []string{"client_id"}, ConflictsWith: []string{"api_token"}, Description: "Your Auth0 client secret. " + @@ -73,7 +73,7 @@ func New() *schema.Provider { "api_token": { Type: schema.TypeString, Optional: true, - DefaultFunc: schema.EnvDefaultFunc("AUTH0_API_TOKEN", nil), + DefaultFunc: schema.EnvDefaultFunc("AUTH0_API_TOKEN", config.MissingEnvVar), ConflictsWith: []string{"client_id", "client_secret"}, Description: "Your Auth0 [management api access token]" + "(https://auth0.com/docs/security/tokens/access-tokens/management-api-access-tokens). " +