Skip to content

Commit 718b6e2

Browse files
authored
INBOX-2241/Add retries to Terraform provider (#247)
* use retryablehttp * retries now tunable, docs * docs and markdown nits * gofmt
1 parent e4a0e93 commit 718b6e2

6 files changed

Lines changed: 85 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ BUG FIXES
55

66
## 1.13.1 (December 5, 2022)
77
ENHANCEMENTS
8+
89
* HTTP debug logging now includes request/response times and response data
910

1011
BUG FIXES
12+
1113
* Update instead of delete/recreate when changing link attribute of DNS record
1214
* Region names in DNS record metadata now sorted to avoid false differences
1315
* Permission flag change detection fixes [issue 237](https://github.com/ns1-terraform/terraform-provider-ns1/issues/237)
@@ -17,18 +19,21 @@ BUG FIXES
1719

1820
## 1.13.1-pre1 (prerelease) (November 10, 2022)
1921
BUG FIXES
22+
2023
* Update instead of delete/recreate when changing link attribute of DNS record
2124
* Fix documentation typo
2225

2326
## 1.13.0 (November 8, 2022)
2427
ENHANCEMENTS:
28+
2529
* Added importers for datafeed, datasource, notifylist and monitoringjob [#235](https://github.com/ns1-terraform/terraform-provider-ns1/pull/235)
2630
* Added support for additional secondary zone attributes [#233](https://github.com/ns1-terraform/terraform-provider-ns1/pull/233)
2731
* Added DNS view support [#234](https://github.com/ns1-terraform/terraform-provider-ns1/pull/234)
2832
* User-Agent string now provider-specific, can be overridden with `NS1_TF_USER_AGENT` environment variable
2933
* Requires ns1-go v2.7.0
3034

3135
BUG FIXES
36+
3237
* Mitigated a race condition that caused false errors to be returned when verifying a newly-created zone with DNSSEC enabled [#235](https://github.com/ns1-terraform/terraform-provider-ns1/pull/235/files#diff-6951d991dadec97cca66b3e918a78392de104f53e86ce520f478f0cca3653e2f)
3338
* Monitoring job rules can now be deleting by removing them from the resource file (empty rules cannot be explicitly specified due to Terraform limitations) [see ns1-go PR 173](https://github.com/ns1/ns1-go/pull/173/files)
3439
* Better handling of monitoring job region names [#229](https://github.com/ns1-terraform/terraform-provider-ns1/pull/229)
@@ -39,47 +44,57 @@ BUG FIXES
3944
## 1.12.8 (September 12, 2022)
4045

4146
BUG FIXES:
47+
4248
* Sort monitoring job region names alphabetically to avoid unnecessary state pushes [#224](https://github.com/ns1-terraform/terraform-provider-ns1/pull/224)
4349

4450

4551
## 1.12.7 (May 26, 2022)
4652

4753
ENCHANCEMENTS:
54+
4855
* Makes hostmaster field available for use [#213](https://github.com/ns1-terraform/terraform-provider-ns1/pull/213)
4956
* Adds support for CRUD operations on subnets [#210](https://github.com/ns1-terraform/terraform-provider-ns1/pull/210)
5057

5158
## 1.12.6 (April 11, 2022)
5259
ENHANCEMENTS:
60+
5361
* Adds support to override TTL [#209](https://github.com/ns1-terraform/terraform-provider-ns1/pull/209)
5462
* Adds TSIG support [#188](https://github.com/ns1-terraform/terraform-provider-ns1/pull/188)
5563
* Mark API keys as sensitive fields [#192](https://github.com/ns1-terraform/terraform-provider-ns1/pull/192)
5664

5765
BUG FIXES:
66+
5867
* Fixes an issue with subdivision parsing [#207](https://github.com/ns1-terraform/terraform-provider-ns1/pull/207)
5968
* Fixes capitalization issue [#208](https://github.com/ns1-terraform/terraform-provider-ns1/pull/208)
6069

6170
## 1.12.5 (February 01, 2022)
6271
ENHANCEMENTS:
72+
6373
* Updates go version to 1.17 to provide release binaries for darwin arm64
6474

6575
## 1.12.4 (January 27, 2022)
6676
ENHANCEMENTS:
77+
6778
* Resolves subdivision formatting inconsistency with answers meta and regions meta
6879

6980
## 1.12.3 (January 24, 2022)
7081
ENHANCEMENTS:
82+
7183
* Resolves subdivision formatting inconsistency
7284

7385
## 1.12.2 (January 07, 2022)
7486
ENHANCEMENTS:
87+
7588
* Various documentation updates
7689
* Added support for team and user import [#193](https://github.com/ns1-terraform/terraform-provider-ns1/pull/193)
7790

7891
## 1.12.1 (September 23, 2021)
7992
ENHANCEMENTS:
93+
8094
* Added additional validation for notify lists [#180](https://github.com/ns1-terraform/terraform-provider-ns1/pull/180)
8195

8296
BUG FIXES:
97+
8398
* Various documentation updates
8499
* Fixed an issue with changing the order of record filters [#177](https://github.com/ns1-terraform/terraform-provider-ns1/pull/177)
85100
* Fixed an issue with ordering in IP whitelists [#178](https://github.com/ns1-terraform/terraform-provider-ns1/pull/178)
@@ -88,113 +103,138 @@ BUG FIXES:
88103

89104
## 1.12.0 (September 7, 2021)
90105
ENHANCEMENTS:
106+
91107
* Adds support for Pulsar applications [#172](https://github.com/ns1-terraform/terraform-provider-ns1/pull/172)
92108
* Adds support for Pulsar jobs [#173](https://github.com/ns1-terraform/terraform-provider-ns1/pull/173)
93109
* Adds support for `dns_records_deny` and `dns_records_allow` permission fields [#165](https://github.com/ns1-terraform/terraform-provider-ns1/pull/165)
94110
* Adds support for the `mute` field on monitoring jobs [#166](https://github.com/ns1-terraform/terraform-provider-ns1/pull/166)
95111

96112
BUG FIXES:
113+
97114
* Fixed an issue with the `tls_add_verify` field on monitoring jobs [#171](https://github.com/ns1-terraform/terraform-provider-ns1/pull/171)
98115
* Resolved an issue with default permissions [#170](https://github.com/ns1-terraform/terraform-provider-ns1/pull/170)
99116

100117
## 1.11.0 (June 29, 2021)
101118
ENHANCEMENTS:
119+
102120
* Adds support for subdivisions to record resources [#164](https://github.com/ns1-terraform/terraform-provider-ns1/pull/164)
103121
* Adds support for `dns_records_allow` and `dns_records_deny` permissions [#165](https://github.com/ns1-terraform/terraform-provider-ns1/pull/165)
104122
* Adds support for `mute` attribute to monitoring job resorce [#166](https://github.com/ns1-terraform/terraform-provider-ns1/pull/166)
105123

106124
BUG FIXES:
125+
107126
* Make `config` for filter chain of `record` computed if not provided [#167](https://github.com/ns1-terraform/terraform-provider-ns1/pull/167)
108127

109128
## 1.10.3 (June 15, 2021)
110129
ENHANCEMENTS:
130+
111131
* Add more verbose logging output for failed requests [#160](https://github.com/ns1-terraform/terraform-provider-ns1/pull/160)
112132
* Update to documentation to reflect proper usage for monitoring datafeeds [#154](https://github.com/ns1-terraform/terraform-provider-ns1/pull/154)
113133

114134
BUG FIXES:
135+
115136
* Correctly coerce `test_id` config value for datafeed resource used with `thousandeyes` `datasource` [#163](https://github.com/ns1-terraform/terraform-provider-ns1/pull/163)
116137
* Change `notify_failback` field in `monitoringjob` resource default to `true` to match default in api [#161](https://github.com/ns1-terraform/terraform-provider-ns1/pull/161)
117138

118139
## 1.10.2 (May 21, 2021)
119140
ENHANCEMENTS:
141+
120142
* Updates ns1-go dependency to add handling of rate limitting when API returns 4xx error [#159](https://github.com/ns1-terraform/terraform-provider-ns1/pull/159).
121143

122144
## 1.10.1 (April 27, 2021)
123145
BUG FIXES:
146+
124147
* Resolves issue with missing value for Key attribute when creating an apikey joined to a team [#158](https://github.com/ns1-terraform/terraform-provider-ns1/pull/158).
125148

126149
## 1.10.0 (April 22, 2021)
127150
ENHANCEMENTS:
151+
128152
* Adds DS record support [#157](https://github.com/ns1-terraform/terraform-provider-ns1/pull/157).
129153

130154
## 1.9.4 (March 23, 2021)
131155
NOTES:
156+
132157
* Updates docs to clarify `key` is an Attribute and not an Argument [#150](https://github.com/ns1-terraform/terraform-provider-ns1/pull/150).
133158

134159
## 1.9.3 (March 4, 2021)
135160
BUG FIXES:
161+
136162
* Adds missing `account_manage_ip_whitelist` permission [#148](https://github.com/ns1-terraform/terraform-provider-ns1/pull/148).
137163

138164
## 1.9.2 (February 26, 2021)
139165
BUG FIXES:
166+
140167
* Values for `tls_skip_verify` are coerced correctly [#146](https://github.com/ns1-terraform/terraform-provider-ns1/pull/146). Thanks @zahiar!
141168

142169
## 1.9.1 (January 7, 2021)
143170
BUG FIXES:
171+
144172
* Values for IPv6 monitoring job configs are coerced correctly [#141](https://github.com/ns1-terraform/terraform-provider-ns1/pull/141).
145173

146174
## 1.9.0 (September 8, 2020)
147175
FEATURES:
176+
148177
* **New Data Source:** `ns1_record` [#137](https://github.com/ns1-terraform/terraform-provider-ns1/pull/137). Thanks to @zahiar!
149178

150179
## 1.8.6 (August 31, 2020)
151180
ENHANCEMENTS:
181+
152182
* Add additional config field to monitoring job configuration
153183

154184
## 1.8.5 (August 13, 2020)
155185
BUG FIXES:
186+
156187
* Resolves issue with config maps returning floats sometimes
157188

158189
## 1.8.4 (June 24, 2020)
159190
BUG FIXES:
191+
160192
* Resolves an issue where changes involving feed pointers in record answer metadata were not detected ([124](https://github.com/terraform-providers/terraform-provider-ns1/pull/124))
161193

162194
## 1.8.3 (May 21, 2020)
163195
BUG FIXES:
196+
164197
* Resolves issues on record filter and meta fields around boolean values not properly being converted to strings ([123](https://github.com/terraform-providers/terraform-provider-ns1/pull/123)).
165198

166199
## 1.8.2 (May 01, 2020)
167200
NOTES:
201+
168202
* Clarify rate limit documentation ([121](https://github.com/terraform-providers/terraform-provider-ns1/pull/121))
169203
* Replace examples in README with blurb pointing to docs ([120](https://github.com/terraform-providers/terraform-provider-ns1/pull/120))
170204

171205
## 1.8.1 (April 09, 2020)
172206
ENHANCEMENTS
207+
173208
* Change username validation regex to match validation used by NS1 API.([#119](https://github.com/terraform-providers/terraform-provider-ns1/pull/119))
174209

175210
## 1.8.0 (March 19, 2020)
176211

177212
ENHANCEMENTS:
213+
178214
* support for pulsar metadata in record answers ([#116](https://github.com/terraform-providers/terraform-provider-ns1/issues/116))
179215

180216
## 1.7.1 (February 25, 2020)
181217

182218
BUG FIXES:
219+
183220
* Bump ns1-go SDK version to v2.2.1 - resolves an issue with ASNs causing
184221
panics ([#113](https://github.com/terraform-providers/terraform-provider-ns1/pull/113)).
185222
* Fix for IP Prefix ordering - don't show a change when order differs ([#112](https://github.com/terraform-providers/terraform-provider-ns1/pull/112)).
186223

187224
ENHANCEMENTS:
225+
188226
* Validate username field in the provider, so issues with usernames are caught
189227
in the "plan" stage ([#115](https://github.com/terraform-providers/terraform-provider-ns1/pull/115)).
190228

191229
## 1.7.0 (January 28, 2020)
192230

193231
NOTES:
232+
194233
* The `short_answers` attribute on `ns1_record` has had a deprecation warning added to it and will be deprecated in a future release ([#102](https://github.com/terraform-providers/terraform-provider-ns1/pull/102)).
195234
* The project has been tagged as under "active development", in accordance with NS1 standards around public facing repositories ([#109](https://github.com/terraform-providers/terraform-provider-ns1/pull/109)).
196235

197236
ENHANCEMENTS:
237+
198238
* Support for DDI permissions on teams, users, and API keys has been added,
199239
and can be enabled via the new `enable_ddi` configuration option on the provider ([#105](https://github.com/terraform-providers/terraform-provider-ns1/pull/105)).
200240
* Added IP Whitelist support for teams, users, and AIP keys ([#105](https://github.com/terraform-providers/terraform-provider-ns1/pull/105)).
@@ -203,56 +243,66 @@ and can be enabled via the new `enable_ddi` configuration option on the provider
203243
## 1.6.4 (January 06, 2020)
204244

205245
IMPROVEMENTS:
246+
206247
* Updated permissions behavior on user and API key resources to accurately show `terraform plan` differences when the user or key is part of a team and updated documentation accordingly ([#100](https://github.com/terraform-providers/terraform-provider-ns1/pull/100))
207248
* Switched to the Terraform standalone SDK ([#101](https://github.com/terraform-providers/terraform-provider-ns1/pull/101))
208249
* Update resource state management to properly handle disappearing resources ([#99](https://github.com/terraform-providers/terraform-provider-ns1/pull/99))
209250

210251
## 1.6.3 (December 16, 2019)
211252

212253
IMPROVEMENTS:
254+
213255
* Add validation to the zone and domain fields on a record to more clearly indicate invalid inputs containing leading or trailing dots ([#97](https://github.com/terraform-providers/terraform-provider-ns1/pull/97))
214256

215257
## 1.6.2 (December 05, 2019)
216258

217259
ENHANCEMENTS:
260+
218261
* Support URLFWD records ([#96](https://github.com/terraform-providers/terraform-provider-ns1/issues/96))
219262
* Add a "clean" rule to Makefile ([#89](https://github.com/terraform-providers/terraform-provider-ns1/issues/89))
220263

221264
## 1.6.1 (November 13, 2019)
222265

223266
BUG FIXES:
267+
224268
* fix interaction with the `autogenerate_ns_record` flag that was making terraform think a clean resource was dirty ([#85](https://github.com/terraform-providers/terraform-provider-ns1/issues/85))
225269

226270
ENHANCEMENTS:
271+
227272
* docs and example for using `autogenerate_ns_record`. ([#83](https://github.com/terraform-providers/terraform-provider-ns1/issues/83))
228273
* minor improvements to some error messages in tests.
229274
* improve docs around the ordering requirement for zone regions.
230275
* improve docs around provider arguments and environment variables.
231276

232277
IMPROVEMENTS:
278+
233279
* Add a configuration option to the provider to use an alternate strategy to avoid rate limit errors. ([#88](https://github.com/terraform-providers/terraform-provider-ns1/issues/88))
234280

235281
## 1.6.0 (October 16, 2019)
236282

237283
BUG FIXES:
284+
238285
* Pick up a divide by zero fix in the SDK, when rate limiting. Should wait around when hitting limits rather
239286
than falling over, and shouldn't require limiting parallelism to avoid 429 errors. ([#74](https://github.com/terraform-providers/terraform-provider-ns1/issues/74))
240287
* We were explicitly sending defaults for `port` and `notify` fields in `secondaries`, now they are implicit.
241288
Sending the default `port` prevented using IP ranges. ([#82](https://github.com/terraform-providers/terraform-provider-ns1/issues/82))
242289

243290
ENHANCEMENTS:
291+
244292
* Allow secondary zone -> primary zone in-place. Old behavior was to force a new resource (DELETE/PUT) on any
245293
change to secondary. Now the only one that requires a new resource is when a zone _becomes_ a secondary. See
246294
the note in docs. ([#75](https://github.com/terraform-providers/terraform-provider-ns1/issues/75))
247295
* Support for CAA records. ([#78](https://github.com/terraform-providers/terraform-provider-ns1/issues/78))
248296

249297
DEPRECATION:
298+
250299
* We've bumped the CI tests to run under Go 1.12. Provider still works with 1.11, but we're developing on and
251300
targeting 1.12+ ([#76](https://github.com/terraform-providers/terraform-provider-ns1/issues/76))
252301

253302
## 1.5.3 (October 02, 2019)
254303

255304
BUG FIXES:
305+
256306
* Disallow setting SOA fields (refresh, retry, expiry, and nx_ttl) on secondary zones. An API bug allowed
257307
these fields to be set on "create", the API now discards any settings to these fields and sets them to default
258308
values. These fields are now marked as "ConflictsWith" for secondary zones. If you were doing this and tf complains

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ require (
2828
github.com/hashicorp/go-hclog v0.9.2 // indirect
2929
github.com/hashicorp/go-multierror v1.0.0 // indirect
3030
github.com/hashicorp/go-plugin v1.0.1 // indirect
31+
github.com/hashicorp/go-retryablehttp v0.7.1 // indirect
3132
github.com/hashicorp/go-safetemp v1.0.0 // indirect
3233
github.com/hashicorp/go-uuid v1.0.1 // indirect
3334
github.com/hashicorp/go-version v1.2.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uP
8383
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
8484
github.com/hashicorp/go-plugin v1.0.1 h1:4OtAfUGbnKC6yS48p0CtMX2oFYtzFZVv6rok3cRWgnE=
8585
github.com/hashicorp/go-plugin v1.0.1/go.mod h1:++UyYGoz3o5w9ZzAdZxtQKrWWP+iqPBn3cQptSMzBuY=
86+
github.com/hashicorp/go-retryablehttp v0.7.1 h1:sUiuQAnLlbvmExtFQs72iFW/HXeUn8Z1aJLQ4LJJbTQ=
87+
github.com/hashicorp/go-retryablehttp v0.7.1/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
8688
github.com/hashicorp/go-safetemp v1.0.0 h1:2HR189eFNrjHQyENnQMMpCiBAsRxzbTMIgBhEyExpmo=
8789
github.com/hashicorp/go-safetemp v1.0.0/go.mod h1:oaerMy3BhqiTbVye6QuFhFtIceqFoDHxNAB65b+Rj1I=
8890
github.com/hashicorp/go-uuid v1.0.1 h1:fv1ep09latC32wFoVwnqcnKJGnMSdBanPczbHAYm1BE=
@@ -298,8 +300,6 @@ gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8
298300
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
299301
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
300302
gopkg.in/cheggaaa/pb.v1 v1.0.27/go.mod h1:V/YB90LKu/1FcN3WVnfiiE5oMCibMjukxqG/qStrOgw=
301-
gopkg.in/ns1/ns1-go.v2 v2.7.0 h1:dnybfLhXKnuTSm8w+iAPVxV5xWCgSF72KiKAC47O5fQ=
302-
gopkg.in/ns1/ns1-go.v2 v2.7.0/go.mod h1:g664JF7DeMJ5jIKrqJCE98h/o1Gma+5j7YU1r/D6438=
303303
gopkg.in/ns1/ns1-go.v2 v2.7.1 h1:dS3Lo1/D+7AsAhbRrgUEbcx4dPJ6klNQuAncrLOXrDg=
304304
gopkg.in/ns1/ns1-go.v2 v2.7.1/go.mod h1:g664JF7DeMJ5jIKrqJCE98h/o1Gma+5j7YU1r/D6438=
305305
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

ns1/config.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ import (
1414
"strings"
1515
"time"
1616

17+
"github.com/hashicorp/go-retryablehttp"
1718
ns1 "gopkg.in/ns1/ns1-go.v2/rest"
1819
)
1920

2021
var (
2122
clientVersion = "1.13.2-pre1"
2223
providerUserAgent = "tf-ns1" + "/" + clientVersion
24+
defaultRetryMax = 3
2325
)
2426

2527
// Config for NS1 API
@@ -29,12 +31,24 @@ type Config struct {
2931
IgnoreSSL bool
3032
EnableDDI bool
3133
RateLimitParallelism int
34+
RetryMax int
3235
}
3336

3437
// Client returns a new NS1 client.
3538
func (c *Config) Client() (*ns1.Client, error) {
3639
var client *ns1.Client
40+
3741
httpClient := &http.Client{}
42+
retryMax := c.RetryMax
43+
if retryMax >= 0 {
44+
if retryMax == 0 {
45+
retryMax = defaultRetryMax
46+
}
47+
retryClient := retryablehttp.NewClient()
48+
retryClient.RetryMax = retryMax
49+
retryClient.Logger = nil
50+
httpClient = retryClient.StandardClient()
51+
}
3852
decos := []func(*ns1.Client){}
3953

4054
if c.Key == "" {
@@ -73,7 +87,7 @@ func (c *Config) Client() (*ns1.Client, error) {
7387
}
7488

7589
UA := providerUserAgent + "_" + client.UserAgent
76-
log.Printf("[INFO] NS1 Client configured for Endpoint: %s, versions %s", client.Endpoint.String(), UA)
90+
log.Printf("[INFO] NS1 Client configured for Endpoint: %s, versions %s, retries %d", client.Endpoint.String(), UA, c.RetryMax)
7791
if localUA := os.Getenv("NS1_TF_USER_AGENT"); localUA != "" {
7892
client.UserAgent = localUA
7993
} else {

0 commit comments

Comments
 (0)