Skip to content

Commit 3bac7c9

Browse files
feat: consideration for retry v2 (#745)
* add 429 as an retryable status code update * update * Update azapi_data_plane_resource.go * update * Update azapi_resource.go * update * Update azapi_data_plane_resource.go * Update azapi_data_plane_resource.go * Update azapi_data_plane_resource.go * Update azapi_resource_action_ephemeral.go * update * Update azapi_resource.go * Update azapi_data_plane_resource.go * Update azapi_data_plane_resource.go * Update common.go * Update common.go * feat: retryv2 * style: go lint * test: remove old test * feat: update default retry * fix: incorrect doc defaults * fix: make error messages optional * docs: updates following review * feat: add skip external request * docs: remove duplicate sentence * test: fix test and move skip package to correct location * refactor: change name of provider retry attribute * docs: update guide with new attr name * Revert "test: fix test and move skip package to correct location" This reverts commit 3be6445. * Revert "feat: add skip external request" This reverts commit b11892c. * refactor: update retry based on feedback * docs: make docs * chore: lint * feat: adopt agreed 2.3 retry * test: update tests * test: improve tests * fix: make err message required * vendor * docs: docs * chore: refactor client retry configure func due to linter * fix: updates following PR review --------- Co-authored-by: Harry Qu <harryqu@microsoft.com>
1 parent fce9e6a commit 3bac7c9

File tree

247 files changed

+11728
-8459
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

247 files changed

+11728
-8459
lines changed

docs/data-sources/resource.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ output "quarantine_policy" {
108108
```
109109

110110
To learn more about JMESPath, visit [JMESPath](https://jmespath.org/).
111-
- `retry` (Attributes) The retry block supports the following arguments: (see [below for nested schema](#nestedatt--retry))
111+
- `retry` (Attributes) The retry object supports the following attributes: (see [below for nested schema](#nestedatt--retry))
112112
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
113113

114114
### Read-Only
@@ -136,7 +136,7 @@ To learn more about JMESPath, visit [JMESPath](https://jmespath.org/).
136136

137137
Required:
138138

139-
- `error_message_regex` (List of String) A list of regular expressions to match against error messages. If any of the regular expressions match, the error is considered retryable.
139+
- `error_message_regex` (List of String) A list of regular expressions to match against error messages. If any of the regular expressions match, the request will be retried.
140140

141141
Optional:
142142

docs/data-sources/resource_action.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ data "azapi_resource_action" "example" {
8787
```
8888

8989
To learn more about JMESPath, visit [JMESPath](https://jmespath.org/).
90-
- `retry` (Attributes) The retry block supports the following arguments: (see [below for nested schema](#nestedatt--retry))
90+
- `retry` (Attributes) The retry object supports the following attributes: (see [below for nested schema](#nestedatt--retry))
9191
- `sensitive_response_export_values` (Dynamic) The attribute can accept either a list or a map.
9292

9393
- **List**: A list of paths that need to be exported from the response body. Setting it to `["*"]` will export the full response body. Here's an example. If it sets to `["properties.loginServer", "properties.policies.quarantinePolicy.status"]`, it will set the following HCL object to the computed property sensitive_output.
@@ -154,7 +154,7 @@ To learn more about JMESPath, visit [JMESPath](https://jmespath.org/).
154154

155155
Required:
156156

157-
- `error_message_regex` (List of String) A list of regular expressions to match against error messages. If any of the regular expressions match, the error is considered retryable.
157+
- `error_message_regex` (List of String) A list of regular expressions to match against error messages. If any of the regular expressions match, the request will be retried.
158158

159159
Optional:
160160

docs/data-sources/resource_list.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ data "azapi_resource_list" "listSubnetsByVnet" {
113113
```
114114

115115
To learn more about JMESPath, visit [JMESPath](https://jmespath.org/).
116-
- `retry` (Attributes) The retry block supports the following arguments: (see [below for nested schema](#nestedatt--retry))
116+
- `retry` (Attributes) The retry object supports the following attributes: (see [below for nested schema](#nestedatt--retry))
117117
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
118118

119119
### Read-Only
@@ -138,7 +138,7 @@ To learn more about JMESPath, visit [JMESPath](https://jmespath.org/).
138138

139139
Required:
140140

141-
- `error_message_regex` (List of String) A list of regular expressions to match against error messages. If any of the regular expressions match, the error is considered retryable.
141+
- `error_message_regex` (List of String) A list of regular expressions to match against error messages. If any of the regular expressions match, the request will be retried.
142142

143143
Optional:
144144

docs/ephemeral-resources/resource_action.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ ephemeral "azapi_resource_action" "listKeys" {
9898
```
9999

100100
To learn more about JMESPath, visit [JMESPath](https://jmespath.org/).
101-
- `retry` (Attributes) The retry block supports the following arguments: (see [below for nested schema](#nestedatt--retry))
101+
- `retry` (Attributes) The retry object supports the following attributes: (see [below for nested schema](#nestedatt--retry))
102102
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
103103

104104
### Read-Only
@@ -123,7 +123,7 @@ To learn more about JMESPath, visit [JMESPath](https://jmespath.org/).
123123

124124
Required:
125125

126-
- `error_message_regex` (List of String) A list of regular expressions to match against error messages. If any of the regular expressions match, the error is considered retryable.
126+
- `error_message_regex` (List of String) A list of regular expressions to match against error messages. If any of the regular expressions match, the request will be retried.
127127

128128
Optional:
129129

docs/guides/feature_customized_retry.md

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,64 @@ description: |-
66
77
---
88

9-
The AzAPI provider can digest the intermittent API errors and retry the requests based on the customized retry configuration. This feature is useful when you need to handle the API errors gracefully and improve the reliability of the Terraform deployments.
9+
## Why retry?
1010

11+
Sometimes, when managing cloud infrastructure, requests to the cloud provider may fail due to transient issues such as network problems, timeouts, eventual consistency, or rate limiting. In these cases, it can be beneficial to retry the request a few times before giving up.
12+
13+
The AzAPI provider can digest these intermittent API errors and retry the requests based on the customized retry configuration. This feature is useful when you need to handle the API errors gracefully and improve the reliability of the Terraform deployments.
1114

1215
## Prerequisites
1316

14-
- [Terraform AzAPI provider](https://registry.terraform.io/providers/azure/azapi) version 2.1.0 or later
17+
- [Terraform AzAPI provider](https://registry.terraform.io/providers/azure/azapi) version 2.1.0 or later. Some features are only available from version 2.3.0.
18+
19+
## Retry configuration
20+
21+
There are two types of retry configurations available in the AzAPI provider:
22+
23+
1. Provider retry configuration
24+
2. Resource-specific retry configuration
25+
26+
### Provider retry configuration
27+
28+
The provider retry configuration is a global configuration that applies to all resources managed by the provider. You can configure the provider retry behavior by setting the following provider values:
29+
30+
- `maximum_busy_retry_attempts`
31+
32+
This value controls the number of times the provider will retry a failed request. The default value is `3`.
33+
A retry will be triggered if the request fails with HTTP 408, 429, 500, 502, 503, or 504.
34+
35+
In the case that the response header contains a `Retry-After` value, the provider will wait for the specified duration before retrying the request.
36+
37+
### Resource-specific retry configuration
38+
39+
In addition to the provider retry configuration, you can also configure the retry behavior for individual resources. This allows you to fine-tune the retry behavior for specific resources.
1540

16-
## Customized Retry for Resource Creation
41+
The resource-specific retry comes after the provider retry, that is to say that the provider retry will be attempted first, and if it fails or exceeds the maximum attempts, the resource-specific retry will be attempted.
42+
Note that the resource-specific retry does not honour the `Retry-After` header and is exponential backoff based.
43+
44+
Resource specific retry is configured using the `retry` attribute.
45+
46+
If you configure a retry configuration, the maximum elapsed time for the retry will be set to the resource's timeout value for that operation (create, update, read, delete).
47+
48+
With `azapi_resource` and `azapi_data_plane_resource`, the provider performs a read operation after the resource has been created so that we can store the read-only values.
49+
50+
The schema of these retry attributes is as follows:
51+
52+
- `error_message_regex` - A list of regular expressions to match against error messages. If any of the regular expressions match, the request will be retried.
53+
- `interval_seconds` - The initial number of seconds to wait before the 1st retry. The default value is `10`.
54+
- `max_interval_seconds` - The maximum number of seconds to wait before retrying a request. The default value is `180`.
55+
- `multiplier` - The multiplier to apply to the interval between retries. The default value is `1.5`.
56+
- `randomization_factor` - The randomization factor to apply to the interval between retries. The default value is `0.5`. The formula for the randomized interval is: `RetryInterval * (random value in range [1 - RandomizationFactor, 1 + RandomizationFactor])`. Set to zero `0.0` for no randomization.
57+
58+
## Default resource-specific retry configuration
59+
60+
If you do not configure any retry values, the provider will use the following:
61+
62+
For the initial create/read/update/delete operation we will only retry on the provider's `maximum_busy_retry_attempts` value.
63+
64+
For the read-after-create, the provider will retry on HTTP 404 and 403 status codes up to the operation timeout. This is logical as, if we have just successfully created the resource, we should not be getting a 404 or 403 on any subsequent GET request.
65+
66+
## Example - Customized Retry for Resource Creation
1767

1868
The virtual network link resource may not be available immediately after the virtual network is created. In this case, you can configure the customized retry configuration to handle the `ResourceNotFound` error and retry the request.
1969

@@ -41,9 +91,9 @@ resource "azapi_resource" "privateDnsZoneLinkBlob" {
4191
}
4292
```
4393

44-
Above configuration is only used for demonstration purposes. From the `2.0.1` version, the AzAPI provider will automatically retry the GET requests when the `ResourceNotFound` error occurs after the resource creation.
94+
Above configuration is only used for demonstration purposes. From the `2.0.1` version, the AzAPI provider will automatically retry the GET requests when the `ResourceNotFound` error occurs after the resource creation.
4595

46-
## Customized Retry for Resource Deletion
96+
## Example - Customized Retry for Resource Deletion
4797

4898
The private DNS zone may not be deleted immediately after the nested virtual network link is deleted. In this case, you can configure the customized retry configuration to handle the `CannotDeleteResource` error and retry the request.
4999

@@ -62,4 +112,3 @@ resource "azapi_resource" "privateDnsZoneQueue" {
62112
}
63113
}
64114
```
65-

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ provider "azapi" {
7272
- `enable_preflight` (Boolean) Enable Preflight Validation. The default is false. When set to true, the provider will use Preflight to do static validation before really deploying a new resource. When set to false, the provider will disable this validation. This can also be sourced from the `ARM_ENABLE_PREFLIGHT` Environment Variable.
7373
- `endpoint` (Attributes List) The Azure API Endpoint Configuration. (see [below for nested schema](#nestedatt--endpoint))
7474
- `environment` (String) The Cloud Environment which should be used. Possible values are `public`, `usgovernment` and `china`. Defaults to `public`. This can also be sourced from the `ARM_ENVIRONMENT` Environment Variable.
75+
- `maximum_busy_retry_attempts` (Number) The maximum number of retries to attempt if the Azure API returns an HTTP 408, 429, 500, 502, 503, or 504 response. The default is `3`. The resource-specific retry configuration may additionally be used to retry on other errors and conditions.
7576
- `oidc_azure_service_connection_id` (String) The Azure Pipelines Service Connection ID to use for authentication. This can also be sourced from the `ARM_ADO_PIPELINE_SERVICE_CONNECTION_ID` or `ARM_OIDC_AZURE_SERVICE_CONNECTION_ID` Environment Variables.
7677
- `oidc_request_token` (String) The bearer token for the request to the OIDC provider. This can also be sourced from the `ARM_OIDC_REQUEST_TOKEN` or `ACTIONS_ID_TOKEN_REQUEST_TOKEN` Environment Variables.
7778
- `oidc_request_url` (String) The URL for the OIDC provider from which to request an ID token. This can also be sourced from the `ARM_OIDC_REQUEST_URL` or `ACTIONS_ID_TOKEN_REQUEST_URL` Environment Variables.

docs/resources/data_plane_resource.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ resource "azapi_data_plane_resource" "example" {
137137
```
138138

139139
To learn more about JMESPath, visit [JMESPath](https://jmespath.org/).
140-
- `retry` (Attributes) The retry block supports the following arguments: (see [below for nested schema](#nestedatt--retry))
140+
- `retry` (Attributes) The retry object supports the following attributes: (see [below for nested schema](#nestedatt--retry))
141141
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
142142
- `update_headers` (Map of String) A mapping of headers to be sent with the update request.
143143
- `update_query_parameters` (Map of List of String) A mapping of query parameters to be sent with the update request.
@@ -164,7 +164,7 @@ To learn more about JMESPath, visit [JMESPath](https://jmespath.org/).
164164

165165
Required:
166166

167-
- `error_message_regex` (List of String) A list of regular expressions to match against error messages. If any of the regular expressions match, the error is considered retryable.
167+
- `error_message_regex` (List of String) A list of regular expressions to match against error messages. If any of the regular expressions match, the request will be retried.
168168

169169
Optional:
170170

docs/resources/resource.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ resource "azapi_resource" "example" {
162162
```
163163

164164
To learn more about JMESPath, visit [JMESPath](https://jmespath.org/).
165-
- `retry` (Attributes) The retry block supports the following arguments: (see [below for nested schema](#nestedatt--retry))
165+
- `retry` (Attributes) The retry object supports the following attributes: (see [below for nested schema](#nestedatt--retry))
166166
- `schema_validation_enabled` (Boolean) Whether enabled the validation on `type` and `body` with embedded schema. Defaults to `true`.
167167
- `tags` (Map of String) A mapping of tags which should be assigned to the Azure resource.
168168
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
@@ -208,7 +208,7 @@ Read-Only:
208208

209209
Required:
210210

211-
- `error_message_regex` (List of String) A list of regular expressions to match against error messages. If any of the regular expressions match, the error is considered retryable.
211+
- `error_message_regex` (List of String) A list of regular expressions to match against error messages. If any of the regular expressions match, the request will be retried.
212212

213213
Optional:
214214

docs/resources/resource_action.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ description: |-
107107
```
108108

109109
To learn more about JMESPath, visit [JMESPath](https://jmespath.org/).
110-
- `retry` (Attributes) The retry block supports the following arguments: (see [below for nested schema](#nestedatt--retry))
110+
- `retry` (Attributes) The retry object supports the following attributes: (see [below for nested schema](#nestedatt--retry))
111111
- `sensitive_response_export_values` (Dynamic) The attribute can accept either a list or a map.
112112

113113
- **List**: A list of paths that need to be exported from the response body. Setting it to `["*"]` will export the full response body. Here's an example. If it sets to `["properties.loginServer", "properties.policies.quarantinePolicy.status"]`, it will set the following HCL object to the computed property output.
@@ -175,7 +175,7 @@ To learn more about JMESPath, visit [JMESPath](https://jmespath.org/).
175175

176176
Required:
177177

178-
- `error_message_regex` (List of String) A list of regular expressions to match against error messages. If any of the regular expressions match, the error is considered retryable.
178+
- `error_message_regex` (List of String) A list of regular expressions to match against error messages. If any of the regular expressions match, the request will be retried.
179179

180180
Optional:
181181

docs/resources/update_resource.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ This resource can manage a subset of any existing Azure resource manager resourc
140140
```
141141

142142
To learn more about JMESPath, visit [JMESPath](https://jmespath.org/).
143-
- `retry` (Attributes) The retry block supports the following arguments: (see [below for nested schema](#nestedatt--retry))
143+
- `retry` (Attributes) The retry object supports the following attributes: (see [below for nested schema](#nestedatt--retry))
144144
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
145145
- `update_headers` (Map of String) A mapping of headers to be sent with the update request.
146146
- `update_query_parameters` (Map of List of String) A mapping of query parameters to be sent with the update request.
@@ -167,7 +167,7 @@ To learn more about JMESPath, visit [JMESPath](https://jmespath.org/).
167167

168168
Required:
169169

170-
- `error_message_regex` (List of String) A list of regular expressions to match against error messages. If any of the regular expressions match, the error is considered retryable.
170+
- `error_message_regex` (List of String) A list of regular expressions to match against error messages. If any of the regular expressions match, the request will be retried.
171171

172172
Optional:
173173

0 commit comments

Comments
 (0)