Skip to content

Commit

Permalink
fix: provider configuration validation (#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
tenthirtyam authored Sep 25, 2024
1 parent e5a87dc commit 9deee5f
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 9deee5f

Please sign in to comment.