Skip to content

Commit

Permalink
add another retry if iam read returns nil (#2629)
Browse files Browse the repository at this point in the history
<!-- This change is generated by MagicModules. -->
/cc @danawillow
  • Loading branch information
modular-magician authored and nat-henderson committed Dec 21, 2018
1 parent 7a3f96a commit 4d9a003
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions google/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ func iamPolicyReadModifyWrite(updater ResourceIamUpdater, modify iamPolicyModify
if err == nil {
fetchBackoff := 1 * time.Second
for successfulFetches := 0; successfulFetches < 3; {
if fetchBackoff > 30*time.Second {
return fmt.Errorf("Error applying IAM policy to %s: Waited too long for propagation.\n", updater.DescribeResource())
}
time.Sleep(fetchBackoff)
log.Printf("[DEBUG]: Retrieving policy for %s\n", updater.DescribeResource())
new_p, err := updater.GetResourceIamPolicy()
if err != nil {
// Quota for Read is pretty limited, so watch out for running out of quota.
Expand All @@ -81,6 +85,12 @@ func iamPolicyReadModifyWrite(updater ResourceIamUpdater, modify iamPolicyModify
return err
}
}
log.Printf("[DEBUG]: Retrieved policy for %s: %+v\n", updater.DescribeResource(), p)
if new_p == nil {
// https://github.com/terraform-providers/terraform-provider-google/issues/2625
fetchBackoff = fetchBackoff * 2
continue
}
modified_p := new_p
// This relies on the fact that `modify` is idempotent: since other changes might have
// happened between the call to set the policy and now, we just need to make sure that
Expand All @@ -94,9 +104,6 @@ func iamPolicyReadModifyWrite(updater ResourceIamUpdater, modify iamPolicyModify
successfulFetches += 1
} else {
fetchBackoff = fetchBackoff * 2
if fetchBackoff > 30*time.Second {
return fmt.Errorf("Error applying IAM policy to %s: Waited too long for propagation.\n", updater.DescribeResource())
}
}
}
break
Expand Down

0 comments on commit 4d9a003

Please sign in to comment.