Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry for google_kms_crypto_key_version #3255

Merged
merged 2 commits into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ func dataSourceGoogleKmsCryptoKeyVersionRead(d *schema.ResourceData, meta interf
return err
}
log.Printf("[DEBUG] Getting public key of CryptoKeyVersion: %#v", url)
res, _ = sendRequest(config, "GET", cryptoKeyId.KeyRingId.Project, url, nil)

res, err = sendRequestWithTimeout(config, "GET", cryptoKeyId.KeyRingId.Project, url, nil, d.Timeout(schema.TimeoutRead), isCryptoKeyVersionsPendingGeneration)

if err != nil {
log.Printf("Error generating public key: %s", err)
return err
}

if err := d.Set("public_key", flattenKmsCryptoKeyVersionPublicKey(res, d)); err != nil {
return fmt.Errorf("Error reading CryptoKeyVersion public key: %s", err)
Expand Down
10 changes: 10 additions & 0 deletions third_party/terraform/utils/error_retry_predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,16 @@ func isAppEngineRetryableError(err error) (bool, string) {
return false, ""
}

// Retry if KMS CryptoKeyVersions returns a 400 for PENDING_GENERATION
func isCryptoKeyVersionsPendingGeneration(err error) (bool, string) {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 400 {
if strings.Contains(gerr.Body, "PENDING_GENERATION") {
return true, "Waiting for pending key generation"
}
}
return false, ""
}

// Retry if getting a resource/operation returns a 404 for specific operations.
// opType should describe the operation for which 404 can be retryable.
func isNotFoundRetryableError(opType string) RetryErrorPredicateFunc {
Expand Down