Skip to content

Commit

Permalink
skip destroyed key versions (#6669)
Browse files Browse the repository at this point in the history
Co-authored-by: Edward Sun <[email protected]>
  • Loading branch information
edwardmedia and Edward Sun authored Oct 10, 2022
1 parent 6efd53f commit 416ff2a
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions mmv1/third_party/terraform/utils/kms_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,18 @@ func clearCryptoKeyVersions(cryptoKeyId *kmsCryptoKeyId, userAgent string, confi
}

for _, version := range versionsResponse.CryptoKeyVersions {
request := &cloudkms.DestroyCryptoKeyVersionRequest{}
destroyCall := versionsClient.Destroy(version.Name, request)
if config.UserProjectOverride {
destroyCall.Header().Set("X-Goog-User-Project", cryptoKeyId.KeyRingId.Project)
}
_, err = destroyCall.Do()

if err != nil {
return err
// skip the versions that have been destroyed earlier
if version.State == "ENABLED" {
request := &cloudkms.DestroyCryptoKeyVersionRequest{}
destroyCall := versionsClient.Destroy(version.Name, request)
if config.UserProjectOverride {
destroyCall.Header().Set("X-Goog-User-Project", cryptoKeyId.KeyRingId.Project)
}
_, err = destroyCall.Do()

if err != nil {
return err
}
}
}

Expand Down

0 comments on commit 416ff2a

Please sign in to comment.