Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add retry for service account creation #11749

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/6053.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
service: re-poll for service account after creation, 404s sometimes due to [eventual consistency](https://cloud.google.com/iam/docs/overview#consistency)
```
26 changes: 26 additions & 0 deletions google/resource_google_service_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,35 @@ func resourceGoogleServiceAccountCreate(d *schema.ResourceData, meta interface{}
return fmt.Errorf("Error reading service account after creation: %s", err)
}

// We poll until the resource is found due to eventual consistency issue
// on part of the api https://cloud.google.com/iam/docs/overview#consistency
err = PollingWaitTime(resourceServiceAccountPollRead(d, meta), PollCheckForExistence, "Creating Service Account", d.Timeout(schema.TimeoutCreate), 1)

if err != nil {
return err
}

return resourceGoogleServiceAccountRead(d, meta)
}

func resourceServiceAccountPollRead(d *schema.ResourceData, meta interface{}) PollReadFunc {
return func() (map[string]interface{}, error) {
config := meta.(*Config)
userAgent, err := generateUserAgentString(d, config.userAgent)
if err != nil {
return nil, err
}

// Confirm the service account exists
_, err = config.NewIamClient(userAgent).Projects.ServiceAccounts.Get(d.Id()).Do()

if err != nil {
return nil, err
}
return nil, nil
}
}

func resourceGoogleServiceAccountRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
userAgent, err := generateUserAgentString(d, config.userAgent)
Expand Down