chore: #64 add system hardening with retry logic for client (#68)
All checks were successful
Publish / Check GoReleaser config (push) Successful in 5s
Publish / Publish provider (push) Successful in 12m49s

- implement RetryRoundTripper

Refs: #64

Reviewed-on: #68
Reviewed-by: Marcel_Henselin <marcel.henselin@stackit.cloud>
Co-authored-by: Andre Harms <andre.harms@stackit.cloud>
Co-committed-by: Andre Harms <andre.harms@stackit.cloud>
This commit is contained in:
Andre_Harms 2026-02-16 09:35:21 +00:00 committed by Marcel_Henselin
parent 20e9b3ca4c
commit d5644ec27f
Signed by: tf-provider.git.onstackit.cloud
GPG key ID: 6D7E8A1ED8955A9C
3 changed files with 512 additions and 1 deletions

View file

@ -6,6 +6,7 @@ import (
"context"
"fmt"
"strings"
"time"
"github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator"
"github.com/hashicorp/terraform-plugin-framework/datasource"
@ -45,6 +46,17 @@ var (
_ provider.Provider = &Provider{}
)
const (
// maxRetries is the maximum number of retries for a failed HTTP request.
maxRetries = 3
// initialDelay is the initial delay before the first retry attempt.
initialDelay = 2 * time.Second
// maxDelay is the maximum delay between retry attempts.
maxDelay = 90 * time.Second
// perTryTimeout is the timeout for each individual HTTP request attempt.
perTryTimeout = 30 * time.Second
)
// Provider is the provider implementation.
type Provider struct {
version string
@ -466,7 +478,7 @@ func (p *Provider) Configure(ctx context.Context, req provider.ConfigureRequest,
providerData.Experiments = experimentValues
}
roundTripper, err := sdkauth.SetupAuth(sdkConfig)
baseRoundTripper, err := sdkauth.SetupAuth(sdkConfig)
if err != nil {
core.LogAndAddError(
ctx,
@ -477,6 +489,14 @@ func (p *Provider) Configure(ctx context.Context, req provider.ConfigureRequest,
return
}
roundTripper := core.NewRetryRoundTripper(
baseRoundTripper,
maxRetries,
initialDelay,
maxDelay,
perTryTimeout,
)
// Make round tripper and custom endpoints available during DataSource and Resource
// type Configure methods.
providerData.RoundTripper = roundTripper