diff --git a/docs/index.md b/docs/index.md index e2643f86..639fa4dc 100644 --- a/docs/index.md +++ b/docs/index.md @@ -70,10 +70,6 @@ resource "solacebroker_msg_vpn_queue" "q" { ## Schema -### Required - -- `url` (String) The base URL of the event broker, for example `https://mybroker.example.org:/`. 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. @@ -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:/`. 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. diff --git a/internal/broker/provider.go b/internal/broker/provider.go index f2bf69a0..08a7e548 100644 --- a/internal/broker/provider.go +++ b/internal/broker/provider.go @@ -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:/`. 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.", @@ -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 } } @@ -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= 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") diff --git a/internal/broker/utilities.go b/internal/broker/utilities.go index 64252268..ff62c698 100644 --- a/internal/broker/utilities.go +++ b/internal/broker/utilities.go @@ -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())