From 25b9dced8c4081f1ac05568a06bdfa775052074f Mon Sep 17 00:00:00 2001 From: Ben Meier Date: Thu, 12 Sep 2024 16:44:39 +0100 Subject: [PATCH] fix: adds 2 http retries to humanitec client requests --- go.mod | 1 + go.sum | 2 ++ internal/provider/provider.go | 5 ++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 68cdff5..e05b9d9 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/hashicorp/terraform-plugin-log v0.9.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 github.com/humanitec/humanitec-go-autogen v0.0.0-20240620130303-6979d29fd1fa + github.com/justinrixx/retryhttp v1.0.1 github.com/stretchr/testify v1.9.0 sigs.k8s.io/yaml v1.4.0 ) diff --git a/go.sum b/go.sum index 41a6dbf..8084f76 100644 --- a/go.sum +++ b/go.sum @@ -136,6 +136,8 @@ github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c= github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo= github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE= +github.com/justinrixx/retryhttp v1.0.1 h1:hTCOBTOcmzR3/W7weMB2YBOl1LlQrqVPIZPAf40p+14= +github.com/justinrixx/retryhttp v1.0.1/go.mod h1:vGs79/0Ut0//fmOGS9HAgI/IbZS6oFV3jFOTCxGEXt0= github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 90529e0..c1895ba 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -11,6 +11,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/provider/schema" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/types" + "github.com/justinrixx/retryhttp" + "github.com/humanitec/humanitec-go-autogen" ) @@ -177,9 +179,10 @@ func (p *HumanitecProvider) Configure(ctx context.Context, req provider.Configur } doer = &http.Client{Transport: tr} } else { - doer = &http.Client{} + doer = &http.Client{Transport: http.DefaultTransport} } + doer.Transport = retryhttp.New(retryhttp.WithTransport(doer.Transport)) client, err := NewHumanitecClient(apiPrefix, token, p.version, doer) if err != nil { resp.Diagnostics.AddError("Unable to create Humanitec client", err.Error())