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 SOLACEBROKER_URL environment variable being ignored #79

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 1 addition & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ resource "solacebroker_msg_vpn_queue" "q" {
<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `url` (String) The base URL of the event broker, for example `https://mybroker.example.org:<semp-service-port>/`. The trailing / can be omitted.

### Optional

- `bearer_token` (String, Sensitive) A bearer token that will be sent in the Authorization header of SEMP requests. Requires TLS transport enabled. Conflicts with username and password.
Expand All @@ -85,6 +81,7 @@ resource "solacebroker_msg_vpn_queue" "q" {
- `retry_max_interval` (String) A [duration](https://pkg.go.dev/maze.io/x/duration#ParseDuration) string indicating the maximum retry interval. The default value is 30s.
- `retry_min_interval` (String) A [duration](https://pkg.go.dev/maze.io/x/duration#ParseDuration) string indicating how long to wait after an initial failed request before the first retry. Exponential backoff is used, up to the limit set by retry_max_interval. The default value is 3s.
- `skip_api_check` (Boolean) Disable validation of the broker SEMP API for supported platform and minimum version. The default value is false.
- `url` (String) The base URL of the event broker, for example `https://mybroker.example.org:<semp-service-port>/`. The trailing / can be omitted.
- `username` (String) The username to connect to the broker with. Requires password and conflicts with bearer_token.

-> All provider configuration values can also be set as environment variables with the same name, but uppercase and with the `SOLACEBROKER_` prefix.
Expand Down
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 @@ -179,6 +179,9 @@ func client(providerData *providerData) (*semp.Client, diag.Diagnostic) {
if err != nil {
return nil, diag.NewErrorDiagnostic("Unable to parse provider attribute", err.Error())
}
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())
}
retries, err := int64WithDefaultFromEnv(providerData.Retries, "retries", semp.DefaultRetries)
if err != nil {
return nil, diag.NewErrorDiagnostic("Unable to parse provider attribute", err.Error())
Expand Down