Skip to content

Commit 937a4f5

Browse files
modular-magiciannat-henderson
authored andcommitted
add another retry if iam read returns nil (#2629)
<!-- This change is generated by MagicModules. --> /cc @danawillow
1 parent d68d3c2 commit 937a4f5

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

google/iam.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ func iamPolicyReadModifyWrite(updater ResourceIamUpdater, modify iamPolicyModify
7171
if err == nil {
7272
fetchBackoff := 1 * time.Second
7373
for successfulFetches := 0; successfulFetches < 3; {
74+
if fetchBackoff > 30*time.Second {
75+
return fmt.Errorf("Error applying IAM policy to %s: Waited too long for propagation.\n", updater.DescribeResource())
76+
}
7477
time.Sleep(fetchBackoff)
78+
log.Printf("[DEBUG]: Retrieving policy for %s\n", updater.DescribeResource())
7579
new_p, err := updater.GetResourceIamPolicy()
7680
if err != nil {
7781
// Quota for Read is pretty limited, so watch out for running out of quota.
@@ -81,6 +85,12 @@ func iamPolicyReadModifyWrite(updater ResourceIamUpdater, modify iamPolicyModify
8185
return err
8286
}
8387
}
88+
log.Printf("[DEBUG]: Retrieved policy for %s: %+v\n", updater.DescribeResource(), p)
89+
if new_p == nil {
90+
// https://github.com/terraform-providers/terraform-provider-google/issues/2625
91+
fetchBackoff = fetchBackoff * 2
92+
continue
93+
}
8494
modified_p := new_p
8595
// This relies on the fact that `modify` is idempotent: since other changes might have
8696
// 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
94104
successfulFetches += 1
95105
} else {
96106
fetchBackoff = fetchBackoff * 2
97-
if fetchBackoff > 30*time.Second {
98-
return fmt.Errorf("Error applying IAM policy to %s: Waited too long for propagation.\n", updater.DescribeResource())
99-
}
100107
}
101108
}
102109
break

0 commit comments

Comments
 (0)