From 8b0ce9911394ea9e41d53359c91a65bc5907eab3 Mon Sep 17 00:00:00 2001 From: Chris Doyle Date: Tue, 26 Nov 2024 14:12:20 +0000 Subject: [PATCH 1/2] fix: fail the provider when env vars are expected but no value is set Signed-off-by: Chris Doyle --- internal/config/config.go | 3 ++- internal/provider/provider.go | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 372f19ce..807e1804 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -22,6 +22,7 @@ import ( ) const providerName = "Terraform-Provider-Auth0" // #nosec G101 +const MissingEnvVar = "MISSING" var version = "dev" @@ -62,7 +63,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 11fea271..1c2c0910 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). " + From eb15523d52fe6bebf50a17c06b90d5932d8ffd70 Mon Sep 17 00:00:00 2001 From: Chris Doyle Date: Tue, 26 Nov 2024 19:09:31 +0000 Subject: [PATCH 2/2] chore: fixing linting error on exported constant Signed-off-by: Chris Doyle --- internal/config/config.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/config/config.go b/internal/config/config.go index 807e1804..7ccf9074 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -22,6 +22,7 @@ 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"