Skip to content

Commit

Permalink
fix: fail the provider when env vars are expected but no value is set
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Doyle <[email protected]>
  • Loading branch information
cdsre committed Nov 26, 2024
1 parent 10b2331 commit 8b0ce99
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
)

const providerName = "Terraform-Provider-Auth0" // #nosec G101
const MissingEnvVar = "MISSING"

Check warning on line 25 in internal/config/config.go

View workflow job for this annotation

GitHub Actions / Checks

exported: exported const MissingEnvVar should have comment or be unexported (revive)

var version = "dev"

Expand Down Expand Up @@ -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,
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

0 comments on commit 8b0ce99

Please sign in to comment.