diff --git a/digitalocean/config/config.go b/digitalocean/config/config.go index 688b62ec7..28fcc76df 100644 --- a/digitalocean/config/config.go +++ b/digitalocean/config/config.go @@ -8,13 +8,11 @@ import ( "net/http" "net/url" "strings" - "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/aws/session" "github.com/digitalocean/godo" - "github.com/hashicorp/go-retryablehttp" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging" "golang.org/x/oauth2" ) @@ -76,30 +74,32 @@ func (c *Config) Client() (*CombinedConfig, error) { userAgent := fmt.Sprintf("Terraform/%s", c.TerraformVersion) var client *http.Client + var godoOpts []godo.ClientOpt + + client = oauth2.NewClient(context.Background(), tokenSrc) if c.HTTPRetryMax > 0 { - retryableClient := retryablehttp.NewClient() - retryableClient.RetryMax = c.HTTPRetryMax - retryableClient.RetryWaitMin = time.Duration(c.HTTPRetryWaitMin * float64(time.Second)) - retryableClient.RetryWaitMax = time.Duration(c.HTTPRetryWaitMax * float64(time.Second)) - - client = retryableClient.StandardClient() - client.Transport = &oauth2.Transport{ - Base: client.Transport, - Source: oauth2.ReuseTokenSource(nil, tokenSrc), + retryConfig := godo.RetryConfig{ + RetryMax: c.HTTPRetryMax, + RetryWaitMin: godo.PtrTo(c.HTTPRetryWaitMin), + RetryWaitMax: godo.PtrTo(c.HTTPRetryWaitMax), + Logger: log.Default(), } - } else { - client = oauth2.NewClient(context.Background(), tokenSrc) + + godoOpts = []godo.ClientOpt{godo.WithRetryAndBackoffs(retryConfig)} } - client.Transport = logging.NewTransport("DigitalOcean", client.Transport) + godoOpts = append(godoOpts, godo.SetUserAgent(userAgent)) - godoOpts := []godo.ClientOpt{godo.SetUserAgent(userAgent)} if c.RequestsPerSecond > 0.0 { godoOpts = append(godoOpts, godo.SetStaticRateLimit(c.RequestsPerSecond)) } godoClient, err := godo.New(client, godoOpts...) + clientTransport := logging.NewTransport("DigitalOcean", godoClient.HTTPClient.Transport) + + godoClient.HTTPClient.Transport = clientTransport + if err != nil { return nil, err } diff --git a/digitalocean/provider.go b/digitalocean/provider.go index 1efc16f35..b16edf641 100644 --- a/digitalocean/provider.go +++ b/digitalocean/provider.go @@ -76,7 +76,7 @@ func Provider() *schema.Provider { "http_retry_max": { Type: schema.TypeInt, Optional: true, - DefaultFunc: schema.EnvDefaultFunc("DIGITALOCEAN_HTTP_RETRY_MAX", 0), + DefaultFunc: schema.EnvDefaultFunc("DIGITALOCEAN_HTTP_RETRY_MAX", 4), Description: "The maximum number of retries on a failed API request.", }, "http_retry_wait_min": { diff --git a/docs/index.md b/docs/index.md index 8e676bd7f..fd47a03b0 100644 --- a/docs/index.md +++ b/docs/index.md @@ -70,7 +70,7 @@ The following arguments are supported: of retries on a failed API request (client errors, 422, 500, 502...), the exponential backoff can be configured by the `http_retry_wait_min` and `http_retry_wait_max` arguments (Defaults to the value of the `DIGITALOCEAN_HTTP_RETRY_MAX` environment variable or - `0`, which means no retries, if unset). + `4` if unset). * `http_retry_wait_min` - (Optional) This can be used to configure the minimum waiting time (**in seconds**) between failed requests for the backoff strategy (Defaults to the value of the `DIGITALOCEAN_HTTP_RETRY_WAIT_MIN` environment diff --git a/vendor/github.com/digitalocean/godo/godo.go b/vendor/github.com/digitalocean/godo/godo.go index 3c8482f35..54e466eae 100644 --- a/vendor/github.com/digitalocean/godo/godo.go +++ b/vendor/github.com/digitalocean/godo/godo.go @@ -644,4 +644,4 @@ func StreamToString(stream io.Reader) string { buf := new(bytes.Buffer) _, _ = buf.ReadFrom(stream) return buf.String() -} +} \ No newline at end of file