Skip to content

Commit

Permalink
Change url to optional to allow setting using env var
Browse files Browse the repository at this point in the history
  • Loading branch information
sreallymatt committed Nov 7, 2024
1 parent 35ac594 commit 8ccd2de
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions internal/broker/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (p *BrokerProvider) Schema(_ context.Context, _ provider.SchemaRequest, res
Attributes: map[string]schema.Attribute{
"url": schema.StringAttribute{
MarkdownDescription: "The base URL of the event broker, for example `https://mybroker.example.org:<semp-service-port>/`. The trailing / can be omitted.",
Required: true,
Optional: true,
},
"username": schema.StringAttribute{
MarkdownDescription: "The username to connect to the broker with. Requires password and conflicts with bearer_token.",
Expand Down Expand Up @@ -106,7 +106,7 @@ func (p *BrokerProvider) Configure(ctx context.Context, req provider.ConfigureRe
// Iterate over the configuration values and check if any of them is not known
for key, value := range configValues {
if !value.IsKnown() {
tflog.Info(ctx, fmt.Sprintf("Configuration has at least one paramter '%s' with unknown value, skipping configuration for now", key))
tflog.Info(ctx, fmt.Sprintf("Configuration has at least one parameter '%s' with unknown value, skipping configuration for now", key))
return
}
}
Expand All @@ -119,6 +119,7 @@ func (p *BrokerProvider) Configure(ctx context.Context, req provider.ConfigureRe
return
}
// Validate the provider configuration
// Line 123 will log solacebroker_url=<null> if `url` is not yet set (i.e loaded from SOLACEBROKER_URL), change?
ctx = tflog.SetField(ctx, "solacebroker_url", strings.Trim(config.Url.String(), "\""))
ctx = tflog.SetField(ctx, "solacebroker_provider_version", p.Version)
tflog.Debug(ctx, "Creating SEMP client")
Expand Down
3 changes: 3 additions & 0 deletions internal/broker/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ func client(providerData *providerData) (*semp.Client, diag.Diagnostic) {
}
}
url, err := stringWithDefaultFromEnv(providerData.Url, "url")
if url == "" {
return nil, diag.NewErrorDiagnostic("`url` attribute must be defined in a provider block or set as an environment variable (`SOLACEBROKER_URL`)", semp.ErrProviderParametersError.Error())
}
if err != nil {
return nil, diag.NewErrorDiagnostic("Unable to parse provider attribute", err.Error())
}
Expand Down

0 comments on commit 8ccd2de

Please sign in to comment.