Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 4s
CI Workflow / Test readiness for publishing provider (pull_request) Failing after 14s
CI Workflow / CI run build and linting (pull_request) Failing after 10s
CI Workflow / Code coverage report (pull_request) Has been skipped
CI Workflow / CI run tests (pull_request) Failing after 57s
47 lines
1.5 KiB
Go Template
47 lines
1.5 KiB
Go Template
package utils
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
{{.PackageName}} "tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pkg_gen/{{.PackageName}}"
|
|
|
|
"github.com/hashicorp/terraform-plugin-framework/diag"
|
|
"github.com/stackitcloud/stackit-sdk-go/core/config"
|
|
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/core"
|
|
"tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/stackit/internal/utils"
|
|
)
|
|
|
|
func ConfigureClient(
|
|
ctx context.Context,
|
|
providerData *core.ProviderData,
|
|
diags *diag.Diagnostics,
|
|
) *{{.PackageName}}.APIClient {
|
|
apiClientConfigOptions := []config.ConfigurationOption{
|
|
config.WithCustomAuth(providerData.RoundTripper),
|
|
utils.UserAgentConfigOption(providerData.Version),
|
|
}
|
|
if providerData.{{.PackageName}}CustomEndpoint != "" {
|
|
apiClientConfigOptions = append(
|
|
apiClientConfigOptions,
|
|
config.WithEndpoint(providerData.{{.PackageName}}CustomEndpoint),
|
|
)
|
|
} else {
|
|
apiClientConfigOptions = append(apiClientConfigOptions, config.WithRegion(providerData.GetRegion()))
|
|
}
|
|
apiClient, err := {{.PackageName}}.NewAPIClient(apiClientConfigOptions...)
|
|
if err != nil {
|
|
core.LogAndAddError(
|
|
ctx,
|
|
diags,
|
|
"Error configuring API client",
|
|
fmt.Sprintf(
|
|
"Configuring client: %v. This is an error related to the provider configuration, not to the resource configuration",
|
|
err,
|
|
),
|
|
)
|
|
return nil
|
|
}
|
|
|
|
return apiClient
|
|
}
|