Skip to content

Commit

Permalink
use same mutex for project_iam_policy as the other project_iam resour…
Browse files Browse the repository at this point in the history
…ces (#1645)
  • Loading branch information
danawillow authored Jun 13, 2018
1 parent d4b4436 commit 0497eec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion google/iam_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package google

import (
"fmt"

"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/cloudresourcemanager/v1"
Expand Down Expand Up @@ -65,7 +66,7 @@ func (u *ProjectIamUpdater) GetResourceId() string {
}

func (u *ProjectIamUpdater) GetMutexKey() string {
return fmt.Sprintf("iam-project-%s", u.resourceId)
return getProjectIamPolicyMutexKey(u.resourceId)
}

func (u *ProjectIamUpdater) DescribeResource() string {
Expand Down
17 changes: 17 additions & 0 deletions google/resource_google_project_iam_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ func resourceGoogleProjectIamPolicyCreate(d *schema.ResourceData, meta interface
if err != nil {
return err
}

mutexKey := getProjectIamPolicyMutexKey(pid)
mutexKV.Lock(mutexKey)
defer mutexKV.Unlock(mutexKey)

// Get the policy in the template
p, err := getResourceIamPolicy(d)
if err != nil {
Expand Down Expand Up @@ -153,6 +158,10 @@ func resourceGoogleProjectIamPolicyUpdate(d *schema.ResourceData, meta interface
return err
}

mutexKey := getProjectIamPolicyMutexKey(pid)
mutexKV.Lock(mutexKey)
defer mutexKV.Unlock(mutexKey)

// Get the policy in the template
p, err := getResourceIamPolicy(d)
if err != nil {
Expand Down Expand Up @@ -220,6 +229,10 @@ func resourceGoogleProjectIamPolicyDelete(d *schema.ResourceData, meta interface
return err
}

mutexKey := getProjectIamPolicyMutexKey(pid)
mutexKV.Lock(mutexKey)
defer mutexKV.Unlock(mutexKey)

// Get the existing IAM policy from the API
ep, err := getProjectIamPolicy(pid, config)
if err != nil {
Expand Down Expand Up @@ -400,3 +413,7 @@ func (b sortableBindings) Swap(i, j int) {
func (b sortableBindings) Less(i, j int) bool {
return b[i].Role < b[j].Role
}

func getProjectIamPolicyMutexKey(pid string) string {
return fmt.Sprintf("iam-project-%s", pid)
}

0 comments on commit 0497eec

Please sign in to comment.