Skip to content

Commit

Permalink
Merge pull request #206 from Charliekenney23/feat/retry-customization
Browse files Browse the repository at this point in the history
add retry delay customization
  • Loading branch information
0xch4z committed Jan 22, 2021
2 parents b0664c3 + 28c4744 commit e11a039
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.14.1 (January 22, 2021)

ENHANCEMENTS:

* add `min_retry_delay_ms` and `max_retry_delay_ms` fields to provider configuration.

## 1.14.0 (January 11, 2021)

BACKWARDS INCOMPATIBILITIES / NOTES:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require (
github.com/bflad/tfproviderlint v0.21.0
github.com/golangci/golangci-lint v1.24.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.0
github.com/linode/linodego v0.24.2
github.com/linode/linodego v0.24.3
github.com/linode/linodego/k8s v0.0.0-20200831124119-58d5d5bb7947
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/linode/linodego v0.20.1/go.mod h1:XOWXRHjqeU2uPS84tKLgfWIfTlv3TYzCS0io4GOQzEI=
github.com/linode/linodego v0.24.2 h1:wj7DO4/8zGEJm6HtGp03L1HLATzmffkwEoifiKIFi0c=
github.com/linode/linodego v0.24.2/go.mod h1:GSBKPpjoQfxEfryoCRcgkuUOCuVtGHWhzI8OMdycNTE=
github.com/linode/linodego v0.24.3 h1:9U/I66zouHIU1tZCFgYK/U4IPJj9ShVu4WqgdGcXcyw=
github.com/linode/linodego v0.24.3/go.mod h1:GSBKPpjoQfxEfryoCRcgkuUOCuVtGHWhzI8OMdycNTE=
github.com/linode/linodego/k8s v0.0.0-20200831124119-58d5d5bb7947 h1:e+tpC7AIiEgfYGEDq9Rjtdybq+V10S6OXzWjeGV/CEk=
github.com/linode/linodego/k8s v0.0.0-20200831124119-58d5d5bb7947/go.mod h1:MWI0tFyaJqRpirMv0VO7CGYT4V3IhHvml2rs/DlRQmY=
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
Expand Down
12 changes: 11 additions & 1 deletion linode/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"os"
"strings"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging"
"github.com/hashicorp/terraform-plugin-sdk/v2/meta"
Expand All @@ -29,7 +30,9 @@ type Config struct {

terraformVersion string

SkipInstanceReadyPoll bool
SkipInstanceReadyPoll bool
MinRetryDelayMilliseconds int
MaxRetryDelayMilliseconds int
}

// Client returns a fully initialized Linode client
Expand Down Expand Up @@ -61,6 +64,13 @@ func (c *Config) Client() linodego.Client {
client.SetBaseURL(DefaultLinodeURL)
}

if c.MinRetryDelayMilliseconds != 0 {
client.SetRetryWaitTime(time.Duration(c.MinRetryDelayMilliseconds) * time.Millisecond)
}
if c.MaxRetryDelayMilliseconds != 0 {
client.SetRetryMaxWaitTime(time.Duration(c.MaxRetryDelayMilliseconds) * time.Millisecond)
}

return client
}

Expand Down
14 changes: 14 additions & 0 deletions linode/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ func Provider() *schema.Provider {
Default: false,
Description: "Skip waiting for a linode_instance resource to be running.",
},

"min_retry_delay_ms": {
Type: schema.TypeInt,
Optional: true,
Description: "Minimum delay in milliseconds before retrying a request.",
},
"max_retry_delay_ms": {
Type: schema.TypeInt,
Optional: true,
Description: "Maximum delay in milliseconds before retrying a request.",
},
},

DataSourcesMap: map[string]*schema.Resource{
Expand Down Expand Up @@ -110,6 +121,9 @@ func providerConfigure(d *schema.ResourceData, terraformVersion string) (interfa
UAPrefix: d.Get("ua_prefix").(string),

SkipInstanceReadyPoll: d.Get("skip_instance_ready_poll").(bool),

MinRetryDelayMilliseconds: d.Get("min_retry_delay_ms").(int),
MaxRetryDelayMilliseconds: d.Get("max_retry_delay_ms").(int),
}
config.terraformVersion = terraformVersion
client := config.Client()
Expand Down
4 changes: 4 additions & 0 deletions website/docs/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ The following keys can be used to configure the provider.

* `skip_instance_ready_poll` - (Optional) Skip waiting for a linode_instance resource to be running.

* `min_retry_delay_ms` - (Optional) Minimum delay in milliseconds before retrying a request.

* `max_retry_delay_ms` - (Optional) Maximum delay in milliseconds before retrying a request.

## Linode Guides

Several [Linode Guides & Tutorials](https://www.linode.com/docs/) are available that explore Terraform usage with Linode resources:
Expand Down

0 comments on commit e11a039

Please sign in to comment.