Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
skip destroyed key versions (#6669) (#1038)
Browse files Browse the repository at this point in the history
Co-authored-by: Edward Sun <[email protected]>
Signed-off-by: Modular Magician <[email protected]>

Signed-off-by: Modular Magician <[email protected]>
Co-authored-by: Edward Sun <[email protected]>
  • Loading branch information
modular-magician and Edward Sun authored Oct 10, 2022
1 parent de1ecb1 commit 5d58db0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
21 changes: 12 additions & 9 deletions converters/google/resources/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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/hashicorp/go-cleanhttp v0.5.2
github.com/hashicorp/terraform-json v0.14.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.18.0
github.com/hashicorp/terraform-provider-google v1.20.1-0.20221010185826-8fa339ef92f0
github.com/hashicorp/terraform-provider-google v1.20.1-0.20221010211601-44355f6a5e2a
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,8 @@ github.com/hashicorp/terraform-plugin-log v0.4.1 h1:xpbmVhvuU3mgHzLetOmx9pkOL2rm
github.com/hashicorp/terraform-plugin-log v0.4.1/go.mod h1:p4R1jWBXRTvL4odmEkFfDdhUjHf9zcs/BCoNHAc7IK4=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.18.0 h1:/cdI5di5XA+N80gXzXF4YcHq36DprBskubk6Z8i26ZQ=
github.com/hashicorp/terraform-plugin-sdk/v2 v2.18.0/go.mod h1:L3SHkD/Q8zPVgXviQmpVwy9nKwpXXZscVIpVEnQ/T50=
github.com/hashicorp/terraform-provider-google v1.20.1-0.20221010185826-8fa339ef92f0 h1:QXmqUuH06Y0INKwm/xWNyzKcjeI6Nw6KwZ/e+SVuAKM=
github.com/hashicorp/terraform-provider-google v1.20.1-0.20221010185826-8fa339ef92f0/go.mod h1:XkWEq9m0whYwjW0vmHmzjskXkneDxOIKcAYQNaAyo7s=
github.com/hashicorp/terraform-provider-google v1.20.1-0.20221010211601-44355f6a5e2a h1:EWlxDwC4OLTufKjRJsaAYT/RWxPbbHvWjxgzZkG5+hM=
github.com/hashicorp/terraform-provider-google v1.20.1-0.20221010211601-44355f6a5e2a/go.mod h1:XkWEq9m0whYwjW0vmHmzjskXkneDxOIKcAYQNaAyo7s=
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c h1:D8aRO6+mTqHfLsK/BC3j5OAoogv1WLRWzY1AaTo3rBg=
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c/go.mod h1:Wn3Na71knbXc1G8Lh+yu/dQWWJeFQEpDeJMtWMtlmNI=
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 h1:HKLsbzeOsfXmKNpr3GiT18XAblV0BjCbzL8KQAMZGa0=
Expand Down

0 comments on commit 5d58db0

Please sign in to comment.