Skip to content

Commit 36e9056

Browse files
authored
fix: IAM Policy 409 concurrent changes error - take 2 (#15995)
1 parent c6aeb9e commit 36e9056

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

mmv1/third_party/terraform/tpgresource/utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ func IsConflictError(err error) bool {
196196
if e.Code == 409 || e.Code == 412 {
197197
return true
198198
}
199+
} else if gErr := (*googleapi.Error)(nil); errors.As(err, &gErr) {
200+
// For cases where the error is not wrapped by errwrap such in 409 IAM concurrency errors.
201+
if gErr.Code == 409 || gErr.Code == 412 {
202+
return true
203+
}
199204
}
200205
return false
201206
}

mmv1/third_party/terraform/tpgresource/utils_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,10 @@ func TestConflictError(t *testing.T) {
973973
t.Error("did not find that a 409 was a conflict error.")
974974
}
975975
if !tpgresource.IsConflictError(errwrap.Wrapf("wrap", confErr)) {
976-
t.Error("did not find that a wrapped 409 was a conflict error.")
976+
t.Error("did not find that a wrapped (errwrap) 409 was a conflict error.")
977+
}
978+
if !tpgresource.IsConflictError(fmt.Errorf("wrap: %w", confErr)) {
979+
t.Error("did not find that a wrapped (fmt.Errorf) 409 was a conflict error.")
977980
}
978981
confErr = &googleapi.Error{
979982
Code: 412,
@@ -984,6 +987,9 @@ func TestConflictError(t *testing.T) {
984987
if !tpgresource.IsConflictError(errwrap.Wrapf("wrap", confErr)) {
985988
t.Error("did not find that a wrapped 412 was a conflict error.")
986989
}
990+
if !tpgresource.IsConflictError(fmt.Errorf("wrap: %w", confErr)) {
991+
t.Error("did not find that a wrapped (fmt.Errorf) 412 was a conflict error.")
992+
}
987993
// skipping negative tests as other cases may be added later.
988994
}
989995

0 commit comments

Comments
 (0)