Don't set IDs in RMW loops.

We don't need to set the ID to "" in read-modify-write helpers, because
once they're done, we read anyways to update state based on the changes.
And that read checks if the binding/member still exists, and does the
SetId("") if it doesn't.

This way, we stick with state only getting set based on the API state,
not by what we think the state will be.
This commit is contained in:
Paddy 2017-07-27 14:29:25 -07:00
parent ac5df40896
commit d3426d5bc6
2 changed files with 3 additions and 4 deletions

View File

@ -155,8 +155,7 @@ func resourceGoogleProjectIamBindingDelete(d *schema.ResourceData, meta interfac
break
}
if toRemove < 0 {
log.Printf("[DEBUG]: Policy bindings for project %q did not include a binding for role %q, no need to delete", pid, binding.Role)
d.SetId("")
log.Printf("[DEBUG]: Policy bindings for project %q did not include a binding for role %q", pid, binding.Role)
return nil
}

View File

@ -146,6 +146,7 @@ func resourceGoogleProjectIamMemberDelete(d *schema.ResourceData, meta interface
break
}
if bindingToRemove < 0 {
log.Printf("[DEBUG]: Binding for role %q does not exist in policy of project %q, so member %q can't be on it.", eMember.Role, pid, eMember.Members[0])
return nil
}
binding := p.Bindings[bindingToRemove]
@ -158,8 +159,7 @@ func resourceGoogleProjectIamMemberDelete(d *schema.ResourceData, meta interface
break
}
if memberToRemove < 0 {
log.Printf("[DEBUG]: Member %q for binding for role %q does not exist in policy of project %q, removing from state.", member.Members[0], member.Role, pid)
d.SetId("")
log.Printf("[DEBUG]: Member %q for binding for role %q does not exist in policy of project %q.", member.Members[0], member.Role, pid)
return nil
}
binding.Members = append(binding.Members[:memberToRemove], binding.Members[memberToRemove+1:]...)