Skip to content

Commit

Permalink
Add retry for google_kms_crypto_key_version (GoogleCloudPlatform#3255)
Browse files Browse the repository at this point in the history
* Add retryTimeDuration for crypto key versions

* Change to sendRequestWithTimeout
  • Loading branch information
c2thorn authored and Nathan Klish committed May 18, 2020
1 parent 81b6c0d commit 84466f3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
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

0 comments on commit 84466f3

Please sign in to comment.