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

Catch 404s when deleting default networks. #2117

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
2 changes: 1 addition & 1 deletion build/terraform
2 changes: 1 addition & 1 deletion build/terraform-beta
6 changes: 5 additions & 1 deletion third_party/terraform/resources/resource_google_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,11 @@ func resourceGoogleProjectCreate(d *schema.ResourceData, meta interface{}) error
}

if err = forceDeleteComputeNetwork(project.ProjectId, "default", config); err != nil {
return fmt.Errorf("Error deleting default network in project %s: %s", project.ProjectId, err)
if isGoogleApiErrorWithCode(err, 404) {
Copy link
Member

Choose a reason for hiding this comment

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

Can't we instead query for the existence of a default network and skip the call to delete if it already doesn't exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could! I chose this way for three reasons:

  1. Either way we'd end up with a network call, except in the most common case we'd end up with two if we checked for existence first
  2. I'm not sure how the current organizational policy works (whether a network is created, then deleted, or if it's just not created at all) or if any future improvements may lead to a network being created then deleting, and I worried about race conditions
  3. Returning a 404 when trying to delete something never seems like an appropriate response, as far as I can think?

Because of that, I couldn't see any benefit to it. Is there a reason you think it'd be better?

Copy link
Member

Choose a reason for hiding this comment

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

I was just thinking about the error on the customer logs related to the delete of the inexistent network, but I'm not strongly opinionated either way.

log.Printf("[DEBUG] Default network not found for project %q, no need to delete it", project.ProjectId)
} else {
return fmt.Errorf("Error deleting default network in project %s: %s", project.ProjectId, err)
}
}
}
return nil
Expand Down