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

Conversation

paddycarver
Copy link
Contributor

As seen in hashicorp/terraform-provider-google#3582, it is now
possible to set an organization policy that removes the default network
from a project when it's created. This means it's now possible that
Terraform's attempt to delete that default network will encounter an
error saying the network is not found. Because what Terraform wanted was
achieved, even if not by Terraform, we shouldn't raise that error, we
should ignore it.

Release Note for Downstream PRs (will be copied)

project: ignore errors when deleting a default network that doesn't exist

@@ -263,7 +263,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.

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician, I work on Magic Modules.
This PR seems not to have generated downstream PRs before, as of c2bccb9.

Pull request statuses

No diff detected in terraform-google-conversion.
No diff detected in Ansible.
No diff detected in Inspec.

New Pull Requests

I built this PR into one or more new PRs on other repositories, and when those are closed, this PR will also be merged and closed.
depends: hashicorp/terraform-provider-google-beta#991
depends: hashicorp/terraform-provider-google#4137

paddycarver and others added 2 commits August 12, 2019 19:30
As seen in hashicorp/terraform-provider-google#3582, it is now
possible to set an organization policy that removes the default network
from a project when it's created. This means it's now possible that
Terraform's attempt to delete that default network will encounter an
error saying the network is not found. Because what Terraform wanted was
achieved, even if not by Terraform, we shouldn't raise that error, we
should ignore it.
Tracked submodules are build/terraform-beta build/terraform-mapper build/terraform build/ansible build/inspec.
@modular-magician modular-magician force-pushed the paddy_skip_default_network branch from c2bccb9 to dc43084 Compare August 12, 2019 19:30
@modular-magician modular-magician merged commit 4e99b70 into GoogleCloudPlatform:master Aug 12, 2019
@SarahFrench SarahFrench deleted the paddy_skip_default_network branch March 26, 2024 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants