From 4d9a003beca8df9aa44911798c0ec6c08e267c1b Mon Sep 17 00:00:00 2001 From: The Magician Date: Tue, 11 Dec 2018 11:04:19 -0800 Subject: [PATCH] add another retry if iam read returns nil (#2629) /cc @danawillow --- google/iam.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/google/iam.go b/google/iam.go index 43789f01289..7af9a1cf8d6 100644 --- a/google/iam.go +++ b/google/iam.go @@ -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. @@ -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 @@ -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