use same mutex for project_iam_policy as the other project_iam resources (#1645)

This commit is contained in:
Dana Hoffman 2018-06-13 12:35:49 -07:00 committed by GitHub
parent d4b4436feb
commit 0497eec580
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package google
import (
"fmt"
"github.com/hashicorp/errwrap"
"github.com/hashicorp/terraform/helper/schema"
"google.golang.org/api/cloudresourcemanager/v1"
@ -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 {

View File

@ -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 {
@ -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 {
@ -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 {
@ -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)
}