in internal/provider/provider.go [76:166]
func (p *CISProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
tflog.Info(ctx, "Configuring CIS client")
var data CISProviderModel
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
}
auth0_endpoint := os.Getenv("AUTH0_ENDPOINT")
auth0_client_id := os.Getenv("AUTH0_CLIENT_ID")
auth0_client_secret := os.Getenv("AUTH0_CLIENT_SECRET")
person_endpoint := os.Getenv("PERSON_ENDPOINT")
if data.Auth0Endpoint.ValueString() != "" {
auth0_endpoint = data.Auth0Endpoint.ValueString()
}
if data.Auth0ClientID.ValueString() != "" {
auth0_client_id = data.Auth0ClientID.ValueString()
}
if data.Auth0ClientSecret.ValueString() != "" {
auth0_client_secret = data.Auth0ClientSecret.ValueString()
}
if data.PersonEndpoint.ValueString() != "" {
person_endpoint = data.PersonEndpoint.ValueString()
}
if auth0_endpoint == "" {
auth0_endpoint = "https://auth.mozilla.auth0.com/oauth/token"
}
if person_endpoint == "" {
person_endpoint = "https://person.api.sso.mozilla.com"
}
tflog.Info(ctx, "Configured CIS client", map[string]any{
"auth0_endpoint": auth0_endpoint,
"auth0_client_id": auth0_client_id,
"auth0_client_secret": auth0_client_secret,
"person_endpoint": person_endpoint,
"HasError()": strconv.FormatBool(resp.Diagnostics.HasError()),
})
// Configuration values are now available.
// if data.Endpoint.IsNull() { /* ... */ }
if auth0_client_id == "" {
resp.Diagnostics.AddAttributeError(
path.Root("auth0_client_id"),
"Missing Auth0 client ID",
"Client ID not found in AUTH0_CLIENT_ID environment variable or provider configuration block auth0_client_id attribute.",
)
}
if auth0_client_secret == "" {
resp.Diagnostics.AddAttributeError(
path.Root("auth0_client_secret"),
"Missing Auth0 client secret",
"Client ID not found in AUTH0_CLIENT_SECRET environment variable or provider configuration block auth0_client_secret attribute.",
)
}
if resp.Diagnostics.HasError() {
return
}
tflog.Info(ctx, "Configuring OAuth2 client")
client := person_api.NewClient(auth0_client_id, auth0_client_secret, "api.sso.mozilla.com", auth0_endpoint, []string{
// "classification:public",
"classification:workgroup",
// "display:none",
// "display:public",
// "display:authenticated",
// "display:vouched",
"display:staff",
}, person_endpoint)
err := client.GetAccessToken(ctx)
if err != nil {
resp.Diagnostics.AddError(
"Failed to initialize OAuth2 Client",
err.Error(),
)
return
}
// Example client configuration for data sources and resources
resp.DataSourceData = client
resp.ResourceData = client
}