Skip to content

Commit

Permalink
Add docs for custom retry handling (GoogleCloudPlatform#12248)
Browse files Browse the repository at this point in the history
  • Loading branch information
roaks3 authored Nov 6, 2024
1 parent e8a9b97 commit cacf5f4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/content/develop/custom-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,28 @@ The parameters the function receives are:
- `d`: Terraform resource data. Use `d.Get("field_name")` to get a field's current value.
- `meta`: Can be cast to a Config object (which can make API calls) using `meta.(*transport_tpg.Config)`

### Custom retry handling

```yaml
error_retry_predicates:
- 'transport_tpg.IamMemberMissing'
error_abort_predicates:
- 'transport_tpg.Is429QuotaError'
```

Use `error_retry_predicates` or `error_abort_predicates` functions to retry or abort when encountering certain error responses. By default, errors are retried using [this list](https://github.com/GoogleCloudPlatform/magic-modules/blob/main/mmv1/third_party/terraform/transport/error_retry_predicates.go#L23) of retry predicates. `error_retry_predicates` can be used to make more errors retryable, while `error_abort_predicates` can be used to prevent errors from being retried.

Both functions use the following signature:

```go
func (err error) (bool, string) {}
```

The function takes an error and returns:
- `bool`: whether the error should be retried/aborted
- `string`: a reason that will be logged

## Replace entire CRUD methods

```yaml
Expand Down
18 changes: 18 additions & 0 deletions docs/content/develop/resource-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,24 @@ async:
resource_inside_response: true
```

### `error_retry_predicates`

An array of function names that determine whether an error is retryable.

```yaml
error_retry_predicates:
- 'transport_tpg.IamMemberMissing'
```

### `error_abort_predicates`

An array of function names that determine whether an error is not retryable.

```yaml
error_abort_predicates:
- 'transport_tpg.Is429QuotaError'
```

## IAM resources

### `iam_policy`
Expand Down

0 comments on commit cacf5f4

Please sign in to comment.