Refactor binding update loop for clarity.

Rewrite the structure of our if statement to make the conditions under
which each portion executes a bit more clear.
This commit is contained in:
Paddy 2017-07-25 11:07:13 -07:00
parent 8a880fdcf8
commit d3f901bfc3

View File

@ -69,7 +69,10 @@ func resourceGoogleProjectIamBindingCreate(d *schema.ResourceData, meta interfac
ep.Bindings = mergeBindings(append(ep.Bindings, p))
log.Printf("[DEBUG]: Setting policy for project %q to %+v\n", pid, ep)
err = setProjectIamPolicy(ep, config, pid)
if err != nil && isConflictError(err) {
if err == nil {
// update was successful, yay
break
} else if isConflitError(err) {
log.Printf("[DEBUG]: Concurrent policy changes, restarting read-modify-write after %s\n", backoff)
time.Sleep(backoff)
backoff = backoff * 2
@ -77,10 +80,8 @@ func resourceGoogleProjectIamBindingCreate(d *schema.ResourceData, meta interfac
return fmt.Errorf("Error applying IAM policy to project %q: too many concurrent policy changes.\n", pid)
}
continue
} else if err != nil {
return fmt.Errorf("Error applying IAM policy to project: %v", err)
}
break
return fmt.Errorf("Error applying IAM policy to project: %v", err)
}
log.Printf("[DEBUG]: Set policy for project %q", pid)
d.SetId(pid + ":" + p.Role)