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

fix: fail the provider when env vars are expected but no value is set #1085

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 3 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
},
Expand All @@ -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. " +
Expand All @@ -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. " +
Expand All @@ -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). " +
Expand Down
Loading