Skip to content

Commit 08b49f3

Browse files
committed
feat(mnq): resource queue
feat(mnq): add read and update queue sqs feat(mnq): sqs queues fix linter issues feat: add nats refactor: underscore unused function parameters docs: add documentation remove unused cassette remove code from another MR fix: ignore `time.Sleep` linter issue docs(mnq): fix sqs example namespace protocol fix: remove double error feat(mnq): set sqs specific url fix(mnq): if name_prefix is not set then it will never be feat(cockpit): don't require token scopes (#1905) feat(mnq): generate queue name feat(mnq): use NATS jetstream and improve tests refactor: replace `retryWhenAWSErrCodeEquals` by `retryOnAWSCode`
1 parent 1d133a9 commit 08b49f3

23 files changed

+6300
-603
lines changed

docs/resources/mnq_queue.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
subcategory: "Messaging and Queuing"
3+
page_title: "Scaleway: scaleway_mnq_queue"
4+
---
5+
6+
# scaleway_mnq_queue
7+
8+
Creates and manages Scaleway Messaging and Queuing queues.
9+
10+
## Examples
11+
12+
### NATS
13+
14+
```hcl
15+
resource "scaleway_mnq_namespace" "main" {
16+
protocol = "nats"
17+
}
18+
19+
resource "scaleway_mnq_credential" "main" {
20+
namespace_id = scaleway_mnq_namespace.main.id
21+
}
22+
23+
resource "scaleway_mnq_queue" "my_queue" {
24+
namespace_id = scaleway_mnq_namespace.main.id
25+
name = "my-queue"
26+
}
27+
```
28+
29+
### SQS
30+
31+
```hcl
32+
resource "scaleway_mnq_namespace" "main" {
33+
protocol = "sqs_sns"
34+
}
35+
36+
resource "scaleway_mnq_credential" "main" {
37+
namespace_id = scaleway_mnq_namespace.main.id
38+
sqs_sns_credentials {
39+
permissions {
40+
can_publish = true
41+
can_receive = true
42+
can_manage = true
43+
}
44+
}
45+
}
46+
47+
resource "scaleway_mnq_queue" "my_queue" {
48+
namespace_id = scaleway_mnq_namespace.main.id
49+
name = "my-queue"
50+
51+
sqs {
52+
access_key = scaleway_mnq_credential.main.sqs_sns_credentials.0.access_key
53+
secret_key = scaleway_mnq_credential.main.sqs_sns_credentials.0.secret_key
54+
}
55+
}
56+
```
57+
58+
### Argument Reference
59+
60+
The following arguments are supported:
61+
62+
* `namespace_id` - (Required) The ID of the Namespace associated to.
63+
64+
* `name` - (Optional) The name of the queue. Either `name` or `name_prefix` is required.
65+
66+
* `name_prefix` - (Optional) The prefix of the queue. Either `name` or `name_prefix` is required.
67+
68+
* `fifo_queue` - (Optional) Whether or not the queue should be a FIFO queue. Defaults to `false`.
69+
70+
* `sqs` - (Optional) The SQS attributes of the queue. See below for details.
71+
~ `access_key` - (Required) The access key of the SQS queue.
72+
~ `secret_key` - (Required) The secret key of the SQS queue.
73+
~ `content_based_deduplication` - (Optional) Whether or not content-based deduplication is enabled for the queue. Defaults to `false`.
74+
~ `max_message_size` - (Optional) The maximum size of messages that can be sent to the queue, in bytes. Must be between 1024 and 262144 bytes. Defaults to 2048 bytes.
75+
~ `message_retention_seconds` - (Optional) The number of seconds that messages are retained in the queue. Must be between 60 and 1209600 seconds. Defaults to 86400 seconds.
76+
~ `receive_wait_time_seconds` - (Optional) The number of seconds that the queue should wait for new messages to arrive before returning an empty response. Defaults to 20 seconds.
77+
~ `visibility_timeout_seconds` - (Optional) The number of seconds that a message is hidden from other consumers after it has been received by one consumer. Must be between 0 and 43200 seconds. Defaults to 120 seconds.
78+
79+
### Attribute Reference
80+
81+
In addition to all arguments above, the following attributes are exported:
82+
83+
* `url` - The URL of the queue.
84+
85+
### Import
86+
87+
Queues can be imported using the `{region}/{namespace-id}/{queue-name}` format:
88+
89+
```shell
90+
$ terraform import scaleway_mnq_queue.my_queue fr-par/11111111111111111111111111111111/my-queue
91+
```

go.mod

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module github.com/scaleway/terraform-provider-scaleway/v2
22

33
require (
4-
github.com/aws/aws-sdk-go v1.44.234
4+
github.com/aws/aws-sdk-go v1.44.237
55
github.com/dnaeon/go-vcr v1.2.0
66
github.com/docker/docker v23.0.3+incompatible
77
github.com/dustin/go-humanize v1.0.1
@@ -13,6 +13,7 @@ require (
1313
github.com/hashicorp/go-retryablehttp v0.7.2
1414
github.com/hashicorp/terraform-plugin-log v0.8.0
1515
github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1
16+
github.com/nats-io/nats.go v1.25.0
1617
github.com/robfig/cron/v3 v3.0.1
1718
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.16
1819
github.com/stretchr/testify v1.8.2
@@ -57,6 +58,9 @@ require (
5758
github.com/mitchellh/reflectwalk v1.0.2 // indirect
5859
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
5960
github.com/morikuni/aec v1.0.0 // indirect
61+
github.com/nats-io/nats-server/v2 v2.9.16 // indirect
62+
github.com/nats-io/nkeys v0.4.4 // indirect
63+
github.com/nats-io/nuid v1.0.1 // indirect
6064
github.com/oklog/run v1.1.0 // indirect
6165
github.com/opencontainers/go-digest v1.0.0 // indirect
6266
github.com/opencontainers/image-spec v1.0.2 // indirect
@@ -66,12 +70,11 @@ require (
6670
github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect
6771
github.com/vmihailenco/tagparser v0.1.2 // indirect
6872
github.com/zclconf/go-cty v1.13.1 // indirect
69-
golang.org/x/crypto v0.7.0 // indirect
73+
golang.org/x/crypto v0.8.0 // indirect
7074
golang.org/x/mod v0.8.0 // indirect
71-
golang.org/x/net v0.8.0 // indirect
72-
golang.org/x/sys v0.6.0 // indirect
73-
golang.org/x/text v0.8.0 // indirect
74-
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
75+
golang.org/x/net v0.9.0 // indirect
76+
golang.org/x/sys v0.7.0 // indirect
77+
golang.org/x/text v0.9.0 // indirect
7578
google.golang.org/appengine v1.6.7 // indirect
7679
google.golang.org/genproto v0.0.0-20220413183235-5e96e2839df9 // indirect
7780
google.golang.org/grpc v1.51.0 // indirect

go.sum

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkE
2525
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
2626
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
2727
github.com/aws/aws-sdk-go v1.31.9/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
28-
github.com/aws/aws-sdk-go v1.44.234 h1:8YbQ5AhpgV/cC7jYX8qS34Am/vcn2ZoIFJ1qIgwOL+0=
29-
github.com/aws/aws-sdk-go v1.44.234/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
28+
github.com/aws/aws-sdk-go v1.44.237 h1:gsmVP8eTB6id4tmEsBPcjLlYi1sXtKA047bSn7kJZAI=
29+
github.com/aws/aws-sdk-go v1.44.237/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
3030
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
3131
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
3232
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
@@ -182,6 +182,7 @@ github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 h1:DowS9hvgy
182182
github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
183183
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
184184
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
185+
github.com/klauspost/compress v1.16.4 h1:91KN02FnsOYhuunwU4ssRe8lc2JosWmizWa91B5v1PU=
185186
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
186187
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
187188
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
@@ -203,6 +204,7 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky
203204
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
204205
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
205206
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
207+
github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g=
206208
github.com/mitchellh/cli v1.1.5/go.mod h1:v8+iFts2sPIKUV1ltktPXMCC8fumSKFItNcD2cLtRR4=
207209
github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw=
208210
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
@@ -223,6 +225,15 @@ github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6/go.mod h1:E2VnQOmVuvZB6U
223225
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
224226
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
225227
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
228+
github.com/nats-io/jwt/v2 v2.4.1 h1:Y35W1dgbbz2SQUYDPCaclXcuqleVmpbRa7646Jf2EX4=
229+
github.com/nats-io/nats-server/v2 v2.9.16 h1:SuNe6AyCcVy0g5326wtyU8TdqYmcPqzTjhkHojAjprc=
230+
github.com/nats-io/nats-server/v2 v2.9.16/go.mod h1:z1cc5Q+kqJkz9mLUdlcSsdYnId4pyImHjNgoh6zxSC0=
231+
github.com/nats-io/nats.go v1.25.0 h1:t5/wCPGciR7X3Mu8QOi4jiJaXaWM8qtkLu4lzGZvYHE=
232+
github.com/nats-io/nats.go v1.25.0/go.mod h1:D2WALIhz7V8M0pH8Scx8JZXlg6Oqz5VG+nQkK8nJdvg=
233+
github.com/nats-io/nkeys v0.4.4 h1:xvBJ8d69TznjcQl9t6//Q5xXuVhyYiSos6RPtvQNTwA=
234+
github.com/nats-io/nkeys v0.4.4/go.mod h1:XUkxdLPTufzlihbamfzQ7mw/VGx6ObUs+0bN5sNvt64=
235+
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
236+
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
226237
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
227238
github.com/oklog/run v1.1.0 h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
228239
github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DVU=
@@ -290,8 +301,8 @@ golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm
290301
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
291302
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
292303
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
293-
golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A=
294-
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
304+
golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ=
305+
golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE=
295306
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
296307
golang.org/x/exp v0.0.0-20230118134722-a68e582fa157 h1:fiNkyhJPUvxbRPbCqY/D9qdjmPzfHcpK3P4bM4gioSY=
297308
golang.org/x/exp v0.0.0-20230118134722-a68e582fa157/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
@@ -326,8 +337,8 @@ golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96b
326337
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
327338
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
328339
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
329-
golang.org/x/net v0.8.0 h1:Zrh2ngAOFYneWTAIAPethzeaQLuHwhuBkuV6ZiRnUaQ=
330-
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
340+
golang.org/x/net v0.9.0 h1:aWJ/m6xSmxWBx+V0XRHTlrYrPG56jKsLdTFmsSsCzOM=
341+
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
331342
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
332343
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
333344
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -367,24 +378,23 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
367378
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
368379
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
369380
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
370-
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
371-
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
381+
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
382+
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
372383
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
373384
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
374385
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
375386
golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ=
376-
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
387+
golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ=
377388
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
378389
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
379390
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
380391
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
381392
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
382393
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
383394
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
384-
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
385-
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
386-
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac h1:7zkz7BUtwNFFqcowJ+RIgu2MaV/MapERkDIy+mwPyjs=
387-
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
395+
golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE=
396+
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
397+
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
388398
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
389399
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
390400
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=

scaleway/errors_object.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,32 @@ const (
2020
ErrCodeNoSuchWebsiteConfiguration = "NoSuchWebsiteConfiguration"
2121
// ErrCodeObjectLockConfigurationNotFoundError object lock configuration not found
2222
ErrCodeObjectLockConfigurationNotFoundError = "ObjectLockConfigurationNotFoundError"
23+
// ErrCodeAuthorizationError authorization error
24+
ErrCodeAuthorizationError = "AuthorizationError"
25+
// ErrCodeInternalException internal exception
26+
ErrCodeInternalException = "InternalException"
27+
// ErrCodeInternalServiceError internal exception error
28+
ErrCodeInternalServiceError = "InternalServiceError"
29+
// ErrCodeInvalidAction invalid action
30+
ErrCodeInvalidAction = "InvalidAction"
31+
// ErrCodeInvalidParameterException invalid parameter exception
32+
ErrCodeInvalidParameterException = "InvalidParameterException"
33+
// ErrCodeInvalidParameterValue invalid parameter value
34+
ErrCodeInvalidParameterValue = "InvalidParameterValue"
35+
// ErrCodeInvalidRequest invalid request
36+
ErrCodeInvalidRequest = "InvalidRequest"
37+
// ErrCodeOperationDisabledException operation disabled exception
38+
ErrCodeOperationDisabledException = "OperationDisabledException"
39+
// ErrCodeOperationNotPermitted operation not permitted
40+
ErrCodeOperationNotPermitted = "OperationNotPermitted"
41+
// ErrCodeUnknownOperationException unknown operation exception
42+
ErrCodeUnknownOperationException = "UnknownOperationException"
43+
// ErrCodeUnsupportedFeatureException = unsupported Feature exception
44+
ErrCodeUnsupportedFeatureException = "UnsupportedFeatureException"
45+
// ErrCodeUnsupportedOperation unsupported operation
46+
ErrCodeUnsupportedOperation = "UnsupportedOperation"
47+
// ErrCodeValidationError validation error
48+
ErrCodeValidationError = "ValidationError"
49+
// ErrCodeValidationException validation exception
50+
ErrCodeValidationException = "ValidationException"
2351
)

scaleway/helpers.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"testing"
1313
"time"
1414

15+
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
1516
"github.com/hashicorp/go-cty/cty"
1617
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
1718
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -954,3 +955,57 @@ func customizeDiffLocalityCheck(keys ...string) schema.CustomizeDiffFunc {
954955
return nil
955956
}
956957
}
958+
959+
type RetryWhenConfig[T any] struct {
960+
Timeout time.Duration
961+
Interval time.Duration
962+
Function func() (T, error)
963+
}
964+
965+
var ErrRetryWhenTimeout = errors.New("timeout reached")
966+
967+
// retryWhen executes the function passed in the configuration object until the timeout is reached or the context is cancelled.
968+
// It will retry if the shouldRetry function returns true. It will stop if the shouldRetry function returns false.
969+
func retryWhen[T any](ctx context.Context, config *RetryWhenConfig[T], shouldRetry func(error) bool) (T, error) { //nolint: ireturn
970+
retryInterval := config.Interval
971+
if DefaultWaitRetryInterval != nil {
972+
retryInterval = *DefaultWaitRetryInterval
973+
}
974+
975+
timer := time.NewTimer(config.Timeout)
976+
977+
for {
978+
result, err := config.Function()
979+
if shouldRetry(err) {
980+
select {
981+
case <-timer.C:
982+
return result, ErrRetryWhenTimeout
983+
case <-ctx.Done():
984+
return result, ctx.Err()
985+
default:
986+
time.Sleep(retryInterval) // lintignore:R018
987+
continue
988+
}
989+
}
990+
991+
return result, err
992+
}
993+
}
994+
995+
// retryWhenAWSErrCodeEquals retries a function when it returns a specific AWS error
996+
func retryWhenAWSErrCodeEquals[T any](ctx context.Context, codes []string, config *RetryWhenConfig[T]) (T, error) { //nolint: ireturn
997+
return retryWhen(ctx, config, func(err error) bool {
998+
return tfawserr.ErrCodeEquals(err, codes...)
999+
})
1000+
}
1001+
1002+
// retryWhenAWSErrCodeNotEquals retries a function until it returns a specific AWS error
1003+
func retryWhenAWSErrCodeNotEquals[T any](ctx context.Context, codes []string, config *RetryWhenConfig[T]) (T, error) { //nolint: ireturn
1004+
return retryWhen(ctx, config, func(err error) bool {
1005+
if err == nil {
1006+
return true
1007+
}
1008+
1009+
return !tfawserr.ErrCodeEquals(err, codes...)
1010+
})
1011+
}

0 commit comments

Comments
 (0)