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

Added a check on provider's configuration for required env vars #1053

Merged
merged 2 commits into from
Oct 24, 2024
Merged
Changes from 1 commit
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
27 changes: 26 additions & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package provider

import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"

Check failure on line 6 in internal/provider/provider.go

View workflow job for this annotation

GitHub Actions / Checks

File is not `goimports`-ed with -local github.com/auth0/terraform-provider-auth0 (goimports)
"os"

"github.com/auth0/terraform-provider-auth0/internal/auth0/flow"
Expand Down Expand Up @@ -172,7 +175,29 @@
},
}

provider.ConfigureContextFunc = config.ConfigureProvider(&provider.TerraformVersion)
provider.ConfigureContextFunc = func(ctx context.Context, d *schema.ResourceData) (interface{}, diag.Diagnostics) {
var diags diag.Diagnostics

// Check required environment variables

Check failure on line 181 in internal/provider/provider.go

View workflow job for this annotation

GitHub Actions / Checks

Comment should end in a period (godot)
requiredEnvVars := []string{"AUTH0_DOMAIN", "AUTH0_CLIENT_ID", "AUTH0_CLIENT_SECRET"}
for _, varName := range requiredEnvVars {
value, exists := os.LookupEnv(varName)
if !exists || value == "" {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: fmt.Sprintf("Missing environment variable: %s", varName),
Detail: fmt.Sprintf("The environment variable %s must be set and cannot be empty.", varName),
})
}
}

if len(diags) > 0 {
return nil, diags
}

// Call the original configuration function if no errors

Check failure on line 198 in internal/provider/provider.go

View workflow job for this annotation

GitHub Actions / Checks

Comment should end in a period (godot)
return config.ConfigureProvider(&provider.TerraformVersion)(ctx, d)
}

return provider
}
Loading