Skip to content

Commit 0497eec

Browse files
authored
use same mutex for project_iam_policy as the other project_iam resources (#1645)
1 parent d4b4436 commit 0497eec

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

google/iam_project.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package google
22

33
import (
44
"fmt"
5+
56
"github.com/hashicorp/errwrap"
67
"github.com/hashicorp/terraform/helper/schema"
78
"google.golang.org/api/cloudresourcemanager/v1"
@@ -65,7 +66,7 @@ func (u *ProjectIamUpdater) GetResourceId() string {
6566
}
6667

6768
func (u *ProjectIamUpdater) GetMutexKey() string {
68-
return fmt.Sprintf("iam-project-%s", u.resourceId)
69+
return getProjectIamPolicyMutexKey(u.resourceId)
6970
}
7071

7172
func (u *ProjectIamUpdater) DescribeResource() string {

google/resource_google_project_iam_policy.go

+17
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ func resourceGoogleProjectIamPolicyCreate(d *schema.ResourceData, meta interface
6161
if err != nil {
6262
return err
6363
}
64+
65+
mutexKey := getProjectIamPolicyMutexKey(pid)
66+
mutexKV.Lock(mutexKey)
67+
defer mutexKV.Unlock(mutexKey)
68+
6469
// Get the policy in the template
6570
p, err := getResourceIamPolicy(d)
6671
if err != nil {
@@ -153,6 +158,10 @@ func resourceGoogleProjectIamPolicyUpdate(d *schema.ResourceData, meta interface
153158
return err
154159
}
155160

161+
mutexKey := getProjectIamPolicyMutexKey(pid)
162+
mutexKV.Lock(mutexKey)
163+
defer mutexKV.Unlock(mutexKey)
164+
156165
// Get the policy in the template
157166
p, err := getResourceIamPolicy(d)
158167
if err != nil {
@@ -220,6 +229,10 @@ func resourceGoogleProjectIamPolicyDelete(d *schema.ResourceData, meta interface
220229
return err
221230
}
222231

232+
mutexKey := getProjectIamPolicyMutexKey(pid)
233+
mutexKV.Lock(mutexKey)
234+
defer mutexKV.Unlock(mutexKey)
235+
223236
// Get the existing IAM policy from the API
224237
ep, err := getProjectIamPolicy(pid, config)
225238
if err != nil {
@@ -400,3 +413,7 @@ func (b sortableBindings) Swap(i, j int) {
400413
func (b sortableBindings) Less(i, j int) bool {
401414
return b[i].Role < b[j].Role
402415
}
416+
417+
func getProjectIamPolicyMutexKey(pid string) string {
418+
return fmt.Sprintf("iam-project-%s", pid)
419+
}

0 commit comments

Comments
 (0)