Skip to content

Commit 1ce86ab

Browse files
Configure retry_wait parameter through the provider configuration (#1017)
* Configure retry_wait parameter through the provider configuration Allow configuring wait time between retries for the underlying client by creating a new optional configuration option for the provider. * Format --------- Co-authored-by: Julien Duchesne <[email protected]>
1 parent 77c2ce2 commit 1ce86ab

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ resource "grafana_oncall_escalation" "example_notify_step" {
213213
- `org_id` (Number, Deprecated) Deprecated: Use the `org_id` attributes on resources instead.
214214
- `retries` (Number) The amount of retries to use for Grafana API and Grafana Cloud API calls. May alternatively be set via the `GRAFANA_RETRIES` environment variable.
215215
- `retry_status_codes` (Set of String) The status codes to retry on for Grafana API and Grafana Cloud API calls. Use `x` as a digit wildcard. Defaults to 429 and 5xx. May alternatively be set via the `GRAFANA_RETRY_STATUS_CODES` environment variable.
216+
- `retry_wait` (Number) The amount of time in seconds to wait between retries for Grafana API and Grafana Cloud API calls. May alternatively be set via the `GRAFANA_RETRY_WAIT` environment variable.
216217
- `sm_access_token` (String, Sensitive) A Synthetic Monitoring access token. May alternatively be set via the `GRAFANA_SM_ACCESS_TOKEN` environment variable.
217218
- `sm_url` (String) Synthetic monitoring backend address. May alternatively be set via the `GRAFANA_SM_URL` environment variable. The correct value for each service region is cited in the [Synthetic Monitoring documentation](https://grafana.com/docs/grafana-cloud/monitor-public-endpoints/private-probes/#probe-api-server-url). Note the `sm_url` value is optional, but it must correspond with the value specified as the `region_slug` in the `grafana_cloud_stack` resource. Also note that when a Terraform configuration contains multiple provider instances managing SM resources associated with the same Grafana stack, specifying an explicit `sm_url` set to the same value for each provider ensures all providers interact with the same SM API.
218219
- `store_dashboard_sha256` (Boolean) Set to true if you want to save only the sha256sum instead of complete dashboard model JSON in the tfstate.

internal/provider/provider.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/url"
1111
"os"
1212
"strings"
13+
"time"
1314

1415
"github.com/hashicorp/go-cleanhttp"
1516
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
@@ -198,6 +199,12 @@ func Provider(version string) func() *schema.Provider {
198199
Description: "The status codes to retry on for Grafana API and Grafana Cloud API calls. Use `x` as a digit wildcard. Defaults to 429 and 5xx. May alternatively be set via the `GRAFANA_RETRY_STATUS_CODES` environment variable.",
199200
Elem: &schema.Schema{Type: schema.TypeString},
200201
},
202+
"retry_wait": {
203+
Type: schema.TypeInt,
204+
Optional: true,
205+
DefaultFunc: schema.EnvDefaultFunc("GRAFANA_RETRY_WAIT", 0),
206+
Description: "The amount of time in seconds to wait between retries for Grafana API and Grafana Cloud API calls. May alternatively be set via the `GRAFANA_RETRY_WAIT` environment variable.",
207+
},
201208
"org_id": {
202209
Type: schema.TypeInt,
203210
Optional: true,
@@ -378,11 +385,12 @@ func createGrafanaClient(d *schema.ResourceData) (string, *gapi.Config, *gapi.Cl
378385
}
379386

380387
cfg := gapi.Config{
381-
Client: cli,
382-
NumRetries: d.Get("retries").(int),
383-
BasicAuth: userInfo,
384-
OrgID: orgID,
385-
APIKey: apiKey,
388+
Client: cli,
389+
NumRetries: d.Get("retries").(int),
390+
RetryTimeout: time.Second * time.Duration(d.Get("retry_wait").(int)),
391+
BasicAuth: userInfo,
392+
OrgID: orgID,
393+
APIKey: apiKey,
386394
}
387395

388396
if v, ok := d.GetOk("retry_status_codes"); ok {
@@ -450,8 +458,9 @@ func createMLClient(url string, grafanaCfg *gapi.Config) (*mlapi.Client, error)
450458

451459
func createCloudClient(d *schema.ResourceData) (*gapi.Client, error) {
452460
cfg := gapi.Config{
453-
APIKey: d.Get("cloud_api_key").(string),
454-
NumRetries: d.Get("retries").(int),
461+
APIKey: d.Get("cloud_api_key").(string),
462+
NumRetries: d.Get("retries").(int),
463+
RetryTimeout: time.Second * time.Duration(d.Get("retry_wait").(int)),
455464
}
456465

457466
var err error

0 commit comments

Comments
 (0)