Skip to content

Commit

Permalink
fix: provider configuration validation
Browse files Browse the repository at this point in the history
Updates the provider configuration to address the issue where the function assumes the configuration is for Cloud Builder if the SDDC Manager username is not provided.

Added a check to ensure that at least one of the configurations is provided. If neither is provided, we can return an appropriate error message.

Ref #238

Signed-off-by: Ryan Johnson <[email protected]>
  • Loading branch information
tenthirtyam committed Sep 18, 2024
1 parent fb8d578 commit afdf43a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,17 @@ func Provider() *schema.Provider {

func providerConfigure(_ context.Context, data *schema.ResourceData) (interface{}, diag.Diagnostics) {
sddcManagerUsername, isVcfUsernameSet := data.GetOk("sddc_manager_username")
cbUsername, isCbUsernameSet := data.GetOk("cloud_builder_username")
allowUnverifiedTLS := data.Get("allow_unverified_tls")

if !isVcfUsernameSet && !isCbUsernameSet {
return nil, diag.Errorf("Either SDDC Manager or Cloud Builder configuration must be provided.")
}

if isVcfUsernameSet {
password, isSetPassword := data.GetOk("sddc_manager_password")
hostName, isSetHost := data.GetOk("sddc_manager_host")
if !isVcfUsernameSet || !isSetPassword || !isSetHost {
if !isSetPassword || !isSetHost {
return nil, diag.Errorf("SDDC Manager username, password, and host must be provided.")
}
var sddcManagerClient = api_client.NewSddcManagerClient(sddcManagerUsername.(string), password.(string),
Expand All @@ -120,15 +126,18 @@ func providerConfigure(_ context.Context, data *schema.ResourceData) (interface{
return nil, diag.FromErr(err)
}
return sddcManagerClient, nil
} else {
cbUsername, isCbUsernameSet := data.GetOk("cloud_builder_username")
}

if isCbUsernameSet {
password, isSetPassword := data.GetOk("cloud_builder_password")
hostName, isSetHost := data.GetOk("cloud_builder_host")
if !isCbUsernameSet || !isSetPassword || !isSetHost {
if !isSetPassword || !isSetHost {
return nil, diag.Errorf("Cloud Builder username, password, and host must be provided.")
}
var cloudBuilderClient = api_client.NewCloudBuilderClient(cbUsername.(string), password.(string),
hostName.(string), allowUnverifiedTLS.(bool))
return cloudBuilderClient, nil
}

return nil, diag.Errorf("Failed to configure the provider. Please check the provider configuration settings.")
}

0 comments on commit afdf43a

Please sign in to comment.