From b41ae2aada25b4edafe76253f7b64078f34f6849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Morcillo=20Mu=C3=B1oz?= Date: Thu, 23 Nov 2023 12:09:13 +0100 Subject: [PATCH] Add poll_function This adds a poll_function argument that can be used to configure the function used during the polling (default: exponential). --- hcloud/plugin_provider.go | 6 +++++- hcloud/provider.go | 14 +++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/hcloud/plugin_provider.go b/hcloud/plugin_provider.go index 443a1223d..70a35a365 100644 --- a/hcloud/plugin_provider.go +++ b/hcloud/plugin_provider.go @@ -56,6 +56,10 @@ func (p *PluginProvider) Schema(_ context.Context, _ provider.SchemaRequest, res Description: "The interval at which actions are polled by the client. Default `500ms`. Increase this interval if you run into rate limiting errors.", Optional: true, }, + "poll_function": schema.StringAttribute{ + Description: "The type of function to be used during the polling.", + Optional: true, + }, }, // TODO: Uncomment once we get rid of the SDK v2 Provider // MarkdownDescription: `The Hetzner Cloud (hcloud) provider is used to interact with the resources supported by @@ -69,6 +73,7 @@ type PluginProviderModel struct { Token types.String `tfsdk:"token"` Endpoint types.String `tfsdk:"endpoint"` PollInterval types.String `tfsdk:"poll_interval"` + PollFunction types.String `tfsdk:"poll_function"` } // Configure is called at the beginning of the provider lifecycle, when @@ -121,7 +126,6 @@ func (p *PluginProvider) Configure(ctx context.Context, req provider.ConfigureRe fmt.Sprintf("An unexpected error was encountered trying to parse the value.\n\n%s", err.Error()), ) } - opts = append(opts, hcloud.WithPollBackoffFunc(hcloud.ExponentialBackoff(2, pollInterval))) } if resp.Diagnostics.HasError() { diff --git a/hcloud/provider.go b/hcloud/provider.go index ae8053b97..82a4b2430 100644 --- a/hcloud/provider.go +++ b/hcloud/provider.go @@ -68,6 +68,13 @@ func Provider() *schema.Provider { Default: "500ms", Description: "The interval at which actions are polled by the client. Default `500ms`. Increase this interval if you run into rate limiting errors.", }, + "poll_function": { + Type: schema.TypeString, + Optional: true, + Default: "exponential", + Description: "The type of function to be used during the polling.", + ExactlyOneOf: []string{"constant", "exponential"}, + }, }, ResourcesMap: map[string]*schema.Resource{ certificate.UploadedResourceType: certificate.UploadedResource(), @@ -139,7 +146,12 @@ func providerConfigure(_ context.Context, d *schema.ResourceData) (interface{}, if err != nil { return nil, hcclient.ErrorToDiag(err) } - opts = append(opts, hcloud.WithPollBackoffFunc(hcloud.ConstantBackoff(pollInterval))) + pollFunction, ok := d.GetOk("poll_function") + if ok && pollFunction == "constant" { + opts = append(opts, hcloud.WithPollBackoffFunc(hcloud.ConstantBackoff(pollInterval))) + } else { + opts = append(opts, hcloud.WithPollBackoffFunc(hcloud.ExponentialBackoff(2, pollInterval))) + } } if logging.LogLevel() != "" { opts = append(opts, hcloud.WithDebugWriter(log.Writer()))