Skip to content

Commit

Permalink
Strip projects/ from the project field, add diff suppress
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
slevenick authored and modular-magician committed Nov 14, 2019
1 parent 05e1db5 commit 2f2f19f
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions google/resource_google_project_iam_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ func resourceGoogleProjectIamPolicy() *schema.Resource {

Schema: map[string]*schema.Schema{
"project": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: compareProjectName,
},
"policy_data": {
Type: schema.TypeString,
Expand All @@ -39,9 +40,14 @@ func resourceGoogleProjectIamPolicy() *schema.Resource {
}
}

func compareProjectName(_, old, new string, _ *schema.ResourceData) bool {
// We can either get "projects/project-id" or "project-id", so strip any prefixes
return GetResourceNameFromSelfLink(old) == GetResourceNameFromSelfLink(new)
}

func resourceGoogleProjectIamPolicyCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
project := d.Get("project").(string)
project := GetResourceNameFromSelfLink(d.Get("project").(string))

mutexKey := getProjectIamPolicyMutexKey(project)
mutexKV.Lock(mutexKey)
Expand All @@ -65,7 +71,7 @@ func resourceGoogleProjectIamPolicyCreate(d *schema.ResourceData, meta interface

func resourceGoogleProjectIamPolicyRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
project := d.Get("project").(string)
project := GetResourceNameFromSelfLink(d.Get("project").(string))

policy, err := getProjectIamPolicy(project, config)
if err != nil {
Expand All @@ -85,7 +91,7 @@ func resourceGoogleProjectIamPolicyRead(d *schema.ResourceData, meta interface{}

func resourceGoogleProjectIamPolicyUpdate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
project := d.Get("project").(string)
project := GetResourceNameFromSelfLink(d.Get("project").(string))

mutexKey := getProjectIamPolicyMutexKey(project)
mutexKV.Lock(mutexKey)
Expand All @@ -109,7 +115,7 @@ func resourceGoogleProjectIamPolicyUpdate(d *schema.ResourceData, meta interface
func resourceGoogleProjectIamPolicyDelete(d *schema.ResourceData, meta interface{}) error {
log.Printf("[DEBUG]: Deleting google_project_iam_policy")
config := meta.(*Config)
project := d.Get("project").(string)
project := GetResourceNameFromSelfLink(d.Get("project").(string))

mutexKey := getProjectIamPolicyMutexKey(project)
mutexKV.Lock(mutexKey)
Expand Down

0 comments on commit 2f2f19f

Please sign in to comment.