waitfor

package
v0.0.52 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

waitfor.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResourceIsAvailable

func ResourceIsAvailable(ctx context.Context, d *schema.ResourceData, resourceType string, resourceID interface{}, checkResourceExists APICallFunc, defaultPropagationTime time.Duration, enableCookieJar bool) (interface{}, diag.Diagnostics)

ResourceIsAvailable employs a retry mechanism with exponential backoff and jitter to wait for a resource to become available. This function is useful in scenarios where resource creation is asynchronous and may not be immediately available after a create API call.

The function uses an APICallFunc to repeatedly check for the existence of the resource, retrying in the face of "resource not found" errors, which are common immediately after resource creation. Other types of errors are not retried and lead to an immediate return.

Exponential backoff helps in efficiently spacing out retry attempts to reduce load on the server and minimize the chance of failures due to rate limiting or server overload. Jitter is added to the backoff duration to prevent retry storms in scenarios with many concurrent operations.

After successfully locating the resource, the function initiates a customizable stabilization period, allowing time for the resource to reach a steady state. The duration of this period is specified by the stabilizationTime parameter. Both the number of retries and the duration of the stabilization period are included in the logging to provide insight into the wait process.

The retry process respects the provided context's deadline, ensuring that the function does not exceed the overall timeout specified for the resource creation operation in Terraform. This approach ensures robustness in transient network issues or temporary server-side unavailability.

Parameters:

  • ctx: The context governing the retry operation, carrying timeout and cancellation signals.
  • d: The Terraform resource data schema instance, providing access to the resource's operational timeout settings.
  • resourceID: The unique identifier of the resource being waited on.
  • checkResourceExists: A function conforming to the APICallFunc type that attempts to fetch the resource by its ID, returning the resource or an error.
  • stabilizationTime: The duration of the stabilization period to wait after the resource is found before concluding the wait process.

Returns:

  • interface{}: The successfully fetched resource if available, needing type assertion to the expected resource type by the caller.
  • diag.Diagnostics: Diagnostic information including any errors encountered during the wait operation, or warnings related to the resource's availability state.

Types

type APICallFunc

type APICallFunc func(interface{}) (interface{}, error)

APICallFunc is a generic function type for API calls that can handle different types of IDs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL