-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Can't destroy VPC (google_compute_network) created by terraform #9812
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
Comments
GCP sometimes creates internal resources (like firewalls) that depend on the network. Some of what's created can depend on local project policy. It's not always easy to tell, I don't know if the Gcloud API can enumerate "things that depend on this network" before trying to delete it. It's even more confusing when one goes to GCP console and deletes it too quickly. The console finds the transitive closure of these dependent resources to delete them, but more are still being created, so the console attempt fails as well. Repeating the delete too quickly can make the problem go on forever. But then some of the dependent resources actually can be deleted without them coming back automatically. What I've found works is to simply wait for a bit so these background processes finish what they are doing, and there's no good way to know when that is, so I just wait a couple of minutes, then delete the network. Usually it gets a good closure on all the resources and gets the job done before the background processes have a chance to make a mess of it again. Seems unlikely that Terraform is going to be able to get around this if the GCP console can't even manage to do so. |
I have replicated above, and have waited over 48 hours with no deletion. I however did find the following article in the docs, about a transitive state lasting 30 days. Looked everywhere for a |
Do you have a serverless function (Cloud Function, Cloud Run, etc.) still referencing the VPC connector? I've run into this issue where the VPC connector was destroyed, but there was a Cloud Function in the project still referencing the "destroyed" connector. Once the Cloud Function was deleted, the VPC network destroy worked properly. |
@KB30497 I have looked everywhere for something still referencing it. I just can't for the life of me find anything. I'm currently 6 days out from the transitive state, i'm curious to see now if it is just a 30 lapse needs to pass. |
Just hit this issue as well:
No references to the Cloud Run service that was removed anywhere in the console. |
I'm having the same issue: from both console and terraform
update: Tried to delete the vpc from the console and I got the same error. Then tried to destroy from terraform and got a new error.
Then I deleted the default route and im back to the head of the snake: "being used by /networkInstances/". |
I have the same problem. Can't find the referred resource in any way. Very annoying. Can't delete manually via the console either. Been waiting for way more than 30 days. Anyone have any luck with this? |
Hey folks, this seems to be a common issue that doesn't stem from the Terraform implementation itself. From what I can tell, there may be dependent resources not visible to users that block deletion. |
Would it make more sense to create a Google Cloud bug requesting better APIs to force-delete networking resources? If those were present then I think these providers could make use of them to resolve. The Cloud Report Issues page has links to view and create bugs related to "Virtual Private Cloud networks". That seems like the most reasonable component: |
Still facing this issue.. not related to the Google Terraform provider implementation though. as @c2thorn mentioned, we're best of by talking to the support team. Perhaps we can close this issue as it's not related to the provider? |
FYI, here's a Google bug report that seems to be the same issue. |
Thanks Nate. These reproduction steps should be really helpful for the Google Team. I hope they see this and it helps speed up the fix. This was first reported to Google on Apr 30, 2021. Google replied that they are "working on it" on Jul 21, 2021. They mention a couple of times they are "working on it" at a product team level (Mar 24, 2022, Apr 21, 2022) yet it still remains unfixed in Jan 2023. Note the issue is marked as a priority P2 with 152 people managing to find it and click "me too". One user reports that they have hit the limit of the amounts of VPC's he can create and so had to move to a new Google Cloud project. I'm disappointed and frustrated with the Google Cloud Platform, I hope it's fixed soon. |
To me the issue seems to be in the serverless vpc connector, the terraform destroy works without the google_vpc_access_connector resource. |
…shicorp#9812) * initial snap commit * yaml lint fix * updated test files and descriptions * updated volume snapshot resource name * removed volumesnapshot * updated VolumeSnapshot file name * filename fixes [upstream:2bc42592095becb5846fd1421a9a1dc3ad7b03f2] Signed-off-by: Modular Magician <magic-modules@google.com>
) (#17138) * initial snap commit * yaml lint fix * updated test files and descriptions * updated volume snapshot resource name * removed volumesnapshot * updated VolumeSnapshot file name * filename fixes [upstream:2bc42592095becb5846fd1421a9a1dc3ad7b03f2] Signed-off-by: Modular Magician <magic-modules@google.com>
This issue still exists. I created GKE cluster and then aN ingress service, which ended up creating multiple NEG in GCP, but now I can't delete the VPC because of this error. The solution for error like below: lists the NEGs, (non beta command also works fine) for each NEG listed, run |
I also tried deleting network from gcp console manually. Got the same error
Same error from |
In my case, I create a cluster with the following plan, and after everything is created, I destroy it. It fails in the deletion of the subnetwork. Adding variable "network" {
description = "The name of the network to create"
type = string
default = "gke-network"
}
provider "google" {
}
data "google_client_config" "default" {}
data "google_compute_network" "vpc_network" {
name = var.network
project = data.google_client_config.default.project
# Manual dependency to fix the issue
depends_on = [google_compute_network.vpc_network]
}
resource "google_compute_network" "vpc_network" {
name = var.network
project = data.google_client_config.default.project
}
resource "google_compute_subnetwork" "vpc_subnet" {
name = "${var.network}-subnet"
project = data.google_client_config.default.project
network = data.google_compute_network.vpc_network.name
ip_cidr_range = "10.0.0.0/16"
# Manual dependency to fix the issue
depends_on = [ google_compute_network.vpc_network ]
secondary_ip_range {
range_name = "${var.network}-subnet-pods"
ip_cidr_range = "10.1.0.0/16"
}
secondary_ip_range {
range_name = "${var.network}-subnet-services"
ip_cidr_range = "10.2.0.0/16"
}
}
provider "kubernetes" {
host = "https://${module.gke.endpoint}"
token = data.google_client_config.default.access_token
cluster_ca_certificate = base64decode(module.gke.ca_certificate)
}
# https://github.com/terraform-google-modules/terraform-google-kubernetes-engine
module "gke" {
source = "terraform-google-modules/kubernetes-engine/google//modules/beta-public-cluster"
project_id = data.google_client_config.default.project
name = var.cluster_name
region = data.google_client_config.default.region
zones = [data.google_client_config.default.zone]
network = data.google_compute_network.vpc_network.name
# Manual dependency to fix the issue
depends_on = [ google_compute_network.vpc_network, google_compute_subnetwork.vpc_subnet ]
subnetwork = "${var.network}-subnet"
ip_range_pods = "${var.network}-subnet-pods"
ip_range_services = "${var.network}-subnet-services"
remove_default_node_pool = false
disable_legacy_metadata_endpoints = false
deletion_protection = false
logging_service = "none"
monitoring_service = "none"
# regional = false
} |
Having the same issue here as well; creating a private cluster using module.gke creates firewall rules and loadbalancing rules that terraform doesn't know about so when trying to destroy the destruction of the network doesn't happen because of the dependency on all these extra things that are created that terraform doesn't know about. |
Same issue. VPC created by Terraform also creates a "serverless ip address", that can be found at VPC Network > IP addresses: Terraform does not track those though. EDIT: I actually think they are created by Cloud Run, not the VPC itself, since I'm using Direct VPC egress in Cloud Run. Even then, they can't be destroyed by Terraform. |
The As long as the connector is present attached to the network, the network cannot be deleted. |
Uh oh!
There was an error while loading. Please reload this page.
Community Note
modular-magician
user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned tohashibot
, a community member has claimed the issue already.Terraform Version
Terraform v1.0.4
on darwin_arm64
Affected Resource(s)
Terraform Configuration Files
Debug Output
`Error: Error waiting for Deleting Network: The network resource 'projects//global/networks/egress-network' is already being used by 'projects/global/networkInstances/v1460259370-47320b4b-55e7-49c0-a22a-43ec4c643d5c'
Expected Behavior
VPC network should be cleanly deleted
Actual Behavior
VPC networks fails to delete, citing it being in use by a "global/networkInstances" obj.
Steps to Reproduce
terraform apply
with above codeterraform apply
References
Am having the same issue as This ServerFault User, but I created the vpc using terraform. Am having trouble getting it to delete cleanly.
b/321386426
The text was updated successfully, but these errors were encountered: