Skip to content

Commit fcd18cd

Browse files
authored
Revert "fix: IAM Policy 409 concurrent changes error (#15825)" (#15972)
1 parent e1e096b commit fcd18cd

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

mmv1/third_party/terraform/tpgresource/utils.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,13 @@ func IsQuotaError(err error) bool {
188188
}
189189

190190
func IsConflictError(err error) bool {
191-
var gerr *googleapi.Error
192-
if errors.As(err, &gerr) {
193-
return gerr.Code == 409 || gerr.Code == 412
191+
if e, ok := err.(*googleapi.Error); ok && (e.Code == 409 || e.Code == 412) {
192+
return true
193+
} else if !ok && errwrap.ContainsType(err, &googleapi.Error{}) {
194+
e := errwrap.GetType(err, &googleapi.Error{}).(*googleapi.Error)
195+
if e.Code == 409 || e.Code == 412 {
196+
return true
197+
}
194198
}
195199
return false
196200
}

mmv1/third_party/terraform/tpgresource/utils_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77
"testing"
88

9+
"github.com/hashicorp/errwrap"
910
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1011

1112
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
@@ -971,7 +972,7 @@ func TestConflictError(t *testing.T) {
971972
if !tpgresource.IsConflictError(confErr) {
972973
t.Error("did not find that a 409 was a conflict error.")
973974
}
974-
if !tpgresource.IsConflictError(fmt.Errorf("wrap: %w", confErr)) {
975+
if !tpgresource.IsConflictError(errwrap.Wrapf("wrap", confErr)) {
975976
t.Error("did not find that a wrapped 409 was a conflict error.")
976977
}
977978
confErr = &googleapi.Error{
@@ -980,7 +981,7 @@ func TestConflictError(t *testing.T) {
980981
if !tpgresource.IsConflictError(confErr) {
981982
t.Error("did not find that a 412 was a conflict error.")
982983
}
983-
if !tpgresource.IsConflictError(fmt.Errorf("wrap: %w", confErr)) {
984+
if !tpgresource.IsConflictError(errwrap.Wrapf("wrap", confErr)) {
984985
t.Error("did not find that a wrapped 412 was a conflict error.")
985986
}
986987
// skipping negative tests as other cases may be added later.

0 commit comments

Comments
 (0)