Documentation ¶
Index ¶
- Constants
- Variables
- func AddQueryParams(rawurl string, params map[string]string) (string, error)
- func ClientWithAdditionalRetries(baseClient *http.Client, predicates ...RetryErrorPredicateFunc) *http.Client
- func DatastoreIndex409Contention(err error) (bool, string)
- func ExternalIpServiceNotActive(err error) (bool, string)
- func FirestoreField409RetryUnderlyingDataChanged(err error) (bool, string)
- func FirestoreIndex409Retry(err error) (bool, string)
- func HandleDataSourceNotFoundError(err error, d *schema.ResourceData, resource, url string) error
- func HandleNotFoundError(err error, d *schema.ResourceData, resource string) error
- func HealthcareDatasetNotInitialized(err error) (bool, string)
- func IamMemberMissing(err error) (bool, string)
- func IamServiceAccountNotFound(err error) (bool, string)
- func IapClient409Operation(err error) (bool, string)
- func Is429QuotaError(err error) (bool, string)
- func IsApiNotEnabledError(err error) bool
- func IsApigeeRetryableError(err error) (bool, string)
- func IsAppEngineRetryableError(err error) (bool, string)
- func IsBigTableRetryableError(err error) (bool, string)
- func IsBigqueryIAMQuotaError(err error) (bool, string)
- func IsCloudRunCreationConflict(err error) (bool, string)
- func IsCryptoKeyVersionsPendingGeneration(err error) (bool, string)
- func IsDataflowJobUpdateRetryableError(err error) (bool, string)
- func IsFingerprintError(err error) (bool, string)
- func IsGoogleApiErrorWithCode(err error, errCode int) bool
- func IsMonitoringConcurrentEditError(err error) (bool, string)
- func IsMonitoringPermissionError(err error) (bool, string)
- func IsPeeringOperationInProgress(err error) (bool, string)
- func IsRetryableError(topErr error, retryPredicates, abortPredicates []RetryErrorPredicateFunc) bool
- func IsSqlOperationInProgressError(err error) (bool, string)
- func IsSwgAutogenRouterRetryable(err error) (bool, string)
- func LockedCall(lockKey string, f func() error) error
- func MetadataRetryWrapper(update func() error) error
- func NewTransportWithDefaultRetries(t http.RoundTripper) *retryTransport
- func NewTransportWithHeaders(baseTransit http.RoundTripper) headerTransportLayer
- func PollingWaitTime(pollF PollReadFunc, checkResponse PollCheckResponseFunc, activity string, ...) error
- func PubsubTopicProjectNotReady(err error) (bool, string)
- func Retry(opt RetryOptions) error
- func RetryWithTargetOccurrences(timeout time.Duration, targetOccurrences int, f resource.RetryFunc) error
- func SendRequest(opt SendRequestOptions) (map[string]interface{}, error)
- func ServiceUsageInternalError160009(err error) (bool, string)
- func ServiceUsageServiceBeingActivated(err error) (bool, string)
- type BatchRequest
- type BatcherCombineFunc
- type BatcherSendFunc
- type BatchingConfig
- type BigtableClientFactory
- func (s BigtableClientFactory) NewAdminClient(project, instance string) (*bigtable.AdminClient, error)
- func (s BigtableClientFactory) NewClient(project, instance string) (*bigtable.Client, error)
- func (s BigtableClientFactory) NewInstanceAdminClient(project string) (*bigtable.InstanceAdminClient, error)
- type MutexKV
- type PollCheckResponseFunc
- type PollReadFunc
- type PollResult
- func ErrorPollResult(err error) PollResult
- func PendingStatusPollResult(status string) PollResult
- func PollCheckForAbsence(_ map[string]interface{}, respErr error) PollResult
- func PollCheckForAbsenceWith403(_ map[string]interface{}, respErr error) PollResult
- func PollCheckForExistence(_ map[string]interface{}, respErr error) PollResult
- func PollCheckForExistenceWith403(_ map[string]interface{}, respErr error) PollResult
- func SuccessPollResult() PollResult
- type RequestBatcher
- type RetryErrorPredicateFunc
- type RetryOptions
- type SendRequestOptions
- type TimeoutError
Constants ¶
const DefaultBatchSendIntervalSec = 3
const METADATA_FINGERPRINT_RETRIES = 10
const TestFakeCredentialsPath = "../test-fixtures/fake_account.json"
Variables ¶
var DefaultRequestTimeout = 5 * time.Minute
var FINGERPRINT_FAIL_ERRORS = []string{"Invalid fingerprint.", "Supplied fingerprint does not match current metadata fingerprint."}
We've encountered a few common fingerprint-related strings; if this is one of them, we're confident this is an error due to fingerprints.
var MutexStore = NewMutexKV()
Global MutexKV
var TimeoutErr = &TimeoutError{timeout: true}
Functions ¶
func ClientWithAdditionalRetries ¶
func ClientWithAdditionalRetries(baseClient *http.Client, predicates ...RetryErrorPredicateFunc) *http.Client
Helper method to create a shallow copy of an HTTP client with a shallow-copied retryTransport s.t. the base HTTP transport is the same (i.e. client connection pools are shared, retryPredicates are different)
func ExternalIpServiceNotActive ¶
Retry the creation of `google_vmwareengine_external_address` resource if the network policy's External IP field is not active yet.
func FirestoreField409RetryUnderlyingDataChanged ¶
relevant for firestore in datastore mode
func FirestoreIndex409Retry ¶
relevant for firestore in datastore mode
func HandleDataSourceNotFoundError ¶
func HandleDataSourceNotFoundError(err error, d *schema.ResourceData, resource, url string) error
func HandleNotFoundError ¶
func HandleNotFoundError(err error, d *schema.ResourceData, resource string) error
func IamMemberMissing ¶
If a permission necessary to provision a resource is created in the same config as the resource itself, the permission may not have propagated by the time terraform attempts to create the resource. This allows those errors to be retried until the timeout expires
func IamServiceAccountNotFound ¶
If a service account is deleted in the middle of updating an IAM policy it can cause the API to return an error. In fine-grained IAM resources we read the policy, modify it, then send it back to the API. Retrying is useful particularly in high-traffic projects. We don't want to retry _every_ time we see this error because the user-provided SA could trigger this too. At the callsite, we should check if the current etag matches the old etag and short-circuit if they do as that indicates the new config is the likely problem.
func IapClient409Operation ¶
func Is429QuotaError ¶
Do not retry if operation returns a 429
func IsApiNotEnabledError ¶
func IsApigeeRetryableError ¶
Concurrent Apigee operations can fail with a 400 error
func IsAppEngineRetryableError ¶
Retry if App Engine operation returns a 409 with a specific message for concurrent operations, or a 404 indicating p4sa has not yet propagated.
func IsBigTableRetryableError ¶
Bigtable uses gRPC and thus does not return errors of type *googleapi.Error. Instead the errors returned are *status.Error. See the types of codes returned here (https://pkg.go.dev/google.golang.org/grpc/codes#Code).
func IsBigqueryIAMQuotaError ¶
Retry if Bigquery operation returns a 403 with a specific message for concurrent operations (which are implemented in terms of 'edit quota').
func IsCloudRunCreationConflict ¶
Cloud Run APIs may return a 409 on create to indicate that a resource has been deleted in the foreground (eg GET and LIST) but not the backing apiserver. When we encounter a 409, we can retry it. Note that due to limitations in MMv1's error_retry_predicates this is currently applied to all requests. We only expect to receive it on create, though.
func IsCryptoKeyVersionsPendingGeneration ¶
Retry if KMS CryptoKeyVersions returns a 400 for PENDING_GENERATION
func IsFingerprintError ¶
Retry the operation if it looks like a fingerprint mismatch.
func IsMonitoringConcurrentEditError ¶
Retry if Monitoring operation returns a 409 with a specific message for concurrent operations.
func IsMonitoringPermissionError ¶
Retry if Monitoring operation returns a 403
func IsRetryableError ¶
func IsRetryableError(topErr error, retryPredicates, abortPredicates []RetryErrorPredicateFunc) bool
func IsSqlOperationInProgressError ¶
Retry if Cloud SQL operation returns a 429 with a specific message for concurrent operations.
func IsSwgAutogenRouterRetryable ¶
Gateway of type 'SECURE_WEB_GATEWAY' automatically creates a router but does not delete it. This router might be re-used by other gateways located in the same network. When multiple gateways are being deleted at the same time, multiple attempts to delete the same router will be triggered and the api throws an error saying the "The resource <router> is not ready".
func LockedCall ¶
func MetadataRetryWrapper ¶
Since the google compute API uses optimistic locking, there is a chance we need to resubmit our updated metadata. To do this, you need to provide an update function that attempts to submit your metadata
func NewTransportWithDefaultRetries ¶
func NewTransportWithDefaultRetries(t http.RoundTripper) *retryTransport
NewTransportWithDefaultRetries constructs a default retryTransport that will retry common temporary errors
func NewTransportWithHeaders ¶
func NewTransportWithHeaders(baseTransit http.RoundTripper) headerTransportLayer
func PollingWaitTime ¶
func PollingWaitTime(pollF PollReadFunc, checkResponse PollCheckResponseFunc, activity string, timeout time.Duration, targetOccurrences int) error
func PubsubTopicProjectNotReady ¶
Cloud PubSub returns a 400 error if a topic's parent project was recently created and an organization policy has not propagated. See https://github.com/hashicorp/terraform-provider-google/issues/4349
func Retry ¶
func Retry(opt RetryOptions) error
func RetryWithTargetOccurrences ¶
func RetryWithTargetOccurrences(timeout time.Duration, targetOccurrences int, f resource.RetryFunc) error
RetryWithTargetOccurrences is a basic wrapper around StateChangeConf that will retry a function until it returns the specified amount of target occurrences continuously. Adapted from the Retry function in the go SDK.
func SendRequest ¶
func SendRequest(opt SendRequestOptions) (map[string]interface{}, error)
func ServiceUsageInternalError160009 ¶
See https://github.com/hashicorp/terraform-provider-google/issues/14691 for details on the error message this handles This is a post-operation error so it uses tpgresource.CommonOpError instead of googleapi.Error
func ServiceUsageServiceBeingActivated ¶
Retry if service usage decides you're activating the same service multiple times. This can happen if a service and a dependent service aren't batched together- eg container.googleapis.com in one request followed by compute.g.c in the next (container relies on compute and implicitly activates it)
Types ¶
type BatchRequest ¶
type BatchRequest struct { // ResourceName represents the underlying resource for which // a request is made. Its format is determined by what SendF expects, but // typically should be the name of the parent GCP resource being changed. ResourceName string // Body is this request's data to be passed to SendF, and may be combined // with other bodies using CombineF. Body interface{} // CombineF function determines how to combine bodies from two batches. CombineF BatcherCombineFunc // SendF function determines how to actually send a batched request to a // third party service. The arguments given to this function are // (ResourceName, Body) where Body may have been combined with other request // Bodies. SendF BatcherSendFunc // ID for debugging request. This should be specific to a single request // (i.e. per Terraform resource) DebugId string }
BatchRequest represents a single request to a global batcher.
type BatcherCombineFunc ¶
type BatcherCombineFunc func(body interface{}, toAdd interface{}) (interface{}, error)
BatcherCombineFunc is a function type for combine existing batches and additional batch data
type BatcherSendFunc ¶
BatcherSendFunc is a function type for sending a batch request
type BatchingConfig ¶
BatchingConfig contains user configuration for controlling batch requests.
type BigtableClientFactory ¶
type BigtableClientFactory struct { UserAgent string TokenSource oauth2.TokenSource BillingProject string UserProjectOverride bool // contains filtered or unexported fields }
func (BigtableClientFactory) NewAdminClient ¶
func (s BigtableClientFactory) NewAdminClient(project, instance string) (*bigtable.AdminClient, error)
func (BigtableClientFactory) NewClient ¶
func (s BigtableClientFactory) NewClient(project, instance string) (*bigtable.Client, error)
func (BigtableClientFactory) NewInstanceAdminClient ¶
func (s BigtableClientFactory) NewInstanceAdminClient(project string) (*bigtable.InstanceAdminClient, error)
type MutexKV ¶
type MutexKV struct {
// contains filtered or unexported fields
}
MutexKV is a simple key/value store for arbitrary mutexes. It can be used to serialize changes across arbitrary collaborators that share knowledge of the keys they must serialize on.
The initial use case is to let aws_security_group_rule resources serialize their access to individual security groups based on SG ID.
func (*MutexKV) Lock ¶
Locks the mutex for the given key. Caller is responsible for calling Unlock for the same key
func (*MutexKV) RLock ¶
Acquires a read-lock on the mutex for the given key. Caller is responsible for calling RUnlock for the same key
type PollCheckResponseFunc ¶
type PollCheckResponseFunc func(resp map[string]interface{}, respErr error) PollResult
Function to check the response from polling once
type PollReadFunc ¶
Function handling for polling for a resource
type PollResult ¶
type PollResult *resource.RetryError
func ErrorPollResult ¶
func ErrorPollResult(err error) PollResult
Helper functions to construct result of single pollRead as return result for a PollCheckResponseFunc
func PendingStatusPollResult ¶
func PendingStatusPollResult(status string) PollResult
func PollCheckForAbsence ¶
func PollCheckForAbsence(_ map[string]interface{}, respErr error) PollResult
PollCheckForAbsence waits for a 404 response, continues polling on a successful response, and returns any other error.
func PollCheckForAbsenceWith403 ¶
func PollCheckForAbsenceWith403(_ map[string]interface{}, respErr error) PollResult
PollCheckForAbsence waits for a 404/403 response, continues polling on a successful response, and returns any other error.
func PollCheckForExistence ¶
func PollCheckForExistence(_ map[string]interface{}, respErr error) PollResult
PollCheckForExistence waits for a successful response, continues polling on 404, and returns any other error.
func PollCheckForExistenceWith403 ¶
func PollCheckForExistenceWith403(_ map[string]interface{}, respErr error) PollResult
PollCheckForExistenceWith403 waits for a successful response, continues polling on 404 or 403, and returns any other error.
func SuccessPollResult ¶
func SuccessPollResult() PollResult
type RequestBatcher ¶
type RequestBatcher struct { sync.Mutex *BatchingConfig // contains filtered or unexported fields }
RequestBatcher keeps track of batched requests globally. It should be created at a provider level. In general, one should be created per service that requires batching to:
- prevent blocking batching for one service due to another,
- minimize the possibility of overlap in batchKey formats (see SendRequestWithTimeout)
func NewRequestBatcher ¶
func NewRequestBatcher(debugId string, ctx context.Context, config *BatchingConfig) *RequestBatcher
Initializes a new batcher.
func (*RequestBatcher) SendRequestWithTimeout ¶
func (b *RequestBatcher) SendRequestWithTimeout(batchKey string, request *BatchRequest, timeout time.Duration) (interface{}, error)
SendRequestWithTimeout is a blocking call for making a single request, run alone or as part of a batch. It manages registering the single request with the batcher and waiting on the result.
Params: batchKey: A string to group batchable requests. It should be unique to the API request being sent, similar to the HTTP request URL with GCP resource ID included in the URL (the caller may choose to use a key with method if needed to diff GET/read and POST/create)
As an example, for google_project_service, the batcher is called to batch services.batchEnable() calls for a project $PROJECT. The calling code uses the template "serviceusage:projects/$PROJECT/services:batchEnable", which mirrors the HTTP request: POST https://serviceusage.googleapis.com/v1/projects/$PROJECT/services:batchEnable
type RetryErrorPredicateFunc ¶
func IsForbiddenIamServiceAccountRetryableError ¶
func IsForbiddenIamServiceAccountRetryableError(opType string) RetryErrorPredicateFunc
Retry if getting a resource/operation returns a 403 for specific IAM Admin API Service Account operations. opType should describe the operation for which it can be retryable. IAM API is eventually consistent and returns 403 Forbidden (instead of 404 Not found) for some operations when a newly created resource is attempted to be read right after the creation and not found.
func IsNotFoundRetryableError ¶
func IsNotFoundRetryableError(opType string) RetryErrorPredicateFunc
Retry if getting a resource/operation returns a 404 for specific operations. opType should describe the operation for which 404 can be retryable.
type RetryOptions ¶
type RetryOptions struct { RetryFunc func() error Timeout time.Duration PollInterval time.Duration ErrorRetryPredicates []RetryErrorPredicateFunc ErrorAbortPredicates []RetryErrorPredicateFunc }
type SendRequestOptions ¶
type SendRequestOptions struct { Config *Config Method string Project string RawURL string UserAgent string Body map[string]any Timeout time.Duration ErrorRetryPredicates []RetryErrorPredicateFunc ErrorAbortPredicates []RetryErrorPredicateFunc }
type TimeoutError ¶
type TimeoutError struct {
// contains filtered or unexported fields
}
func (*TimeoutError) Error ¶
func (e *TimeoutError) Error() string
func (*TimeoutError) Timeout ¶
func (e *TimeoutError) Timeout() bool