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

Retry delete network step while creating a google project. #10046

Merged
merged 1 commit into from
Feb 26, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,13 @@ func resourceGoogleProjectCreate(d *schema.ResourceData, meta interface{}) error
return errwrap.Wrapf("Error enabling the Compute Engine API required to delete the default network: {{err}} ", err)
}

if err = forceDeleteComputeNetwork(d, config, project.ProjectId, "default"); err != nil {
err = forceDeleteComputeNetwork(d, config, project.ProjectId, "default")
// Retry if API is not yet enabled.
if err != nil && transport_tpg.IsGoogleApiErrorWithCode(err, 403) {
time.Sleep(10 * time.Second)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting for future reviewers: Normally we would want to send the request in a retry loop using our standard retry predicates

But forceDeleteComputeNetwork actually involves multiple steps, so a single sleep retry should be fine in this case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we adding the retry here instead of adding retries inside forceDeleteComputeNetwork?

Copy link
Member

@c2thorn c2thorn Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that, but the 403's we're retrying here occur right after project creation + enabling the compute API.
If anything wanted to reuse the function (this is the only use so far), I thought it would be better to keep this case contained to google_project. Open to other ideas though.

err = forceDeleteComputeNetwork(d, config, project.ProjectId, "default")
}
if err != nil {
if transport_tpg.IsGoogleApiErrorWithCode(err, 404) {
log.Printf("[DEBUG] Default network not found for project %q, no need to delete it", project.ProjectId)
} else {
Expand Down
Loading