Skip to content

Commit 518ba7b

Browse files
authored
fix: IAM Policy 409 concurrent changes error (#15825)
1 parent c7a4309 commit 518ba7b

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

mmv1/third_party/terraform/tpgresource/utils.go

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

190190
func IsConflictError(err error) bool {
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-
}
191+
var gerr *googleapi.Error
192+
if errors.As(err, &gerr) {
193+
return gerr.Code == 409 || gerr.Code == 412
198194
}
199195
return false
200196
}

mmv1/third_party/terraform/tpgresource/utils_test.go

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

9-
"github.com/hashicorp/errwrap"
109
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1110

1211
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
@@ -972,7 +971,7 @@ func TestConflictError(t *testing.T) {
972971
if !tpgresource.IsConflictError(confErr) {
973972
t.Error("did not find that a 409 was a conflict error.")
974973
}
975-
if !tpgresource.IsConflictError(errwrap.Wrapf("wrap", confErr)) {
974+
if !tpgresource.IsConflictError(fmt.Errorf("wrap: %w", confErr)) {
976975
t.Error("did not find that a wrapped 409 was a conflict error.")
977976
}
978977
confErr = &googleapi.Error{
@@ -981,7 +980,7 @@ func TestConflictError(t *testing.T) {
981980
if !tpgresource.IsConflictError(confErr) {
982981
t.Error("did not find that a 412 was a conflict error.")
983982
}
984-
if !tpgresource.IsConflictError(errwrap.Wrapf("wrap", confErr)) {
983+
if !tpgresource.IsConflictError(fmt.Errorf("wrap: %w", confErr)) {
985984
t.Error("did not find that a wrapped 412 was a conflict error.")
986985
}
987986
// skipping negative tests as other cases may be added later.

0 commit comments

Comments
 (0)