Skip to content

Commit

Permalink
Catch 404s when deleting default networks.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
paddycarver committed Jul 31, 2019
1 parent bb4c89a commit c2bccb9
Showing 1 changed file with 5 additions and 1 deletion.
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 @@ -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) {
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

0 comments on commit c2bccb9

Please sign in to comment.