Hi, we are using terraform to deploy and destroy envs, we use very old provider and every thing work fine. but when we are updating the provider to the latest when we are deleting the GKE it not deleting firewall rules and the gke-oidc-envoy load balancer. so we can't delete the vpc.
example error:
Hi @yossig-runai,
Welcome to Google Cloud Community!
It sounds like you're experiencing an issue with Kubernetes Engine (GKE) cleanup when using OpenID Connect (OIDC) authentication. Google Cloud sometimes takes time to fully delete network resources, causing a dependency issue.
It seems that the new Terraform provider version isn’t properly managing dependencies during environment teardown. When deleting a Google Kubernetes Engine (GKE) cluster with OIDC enabled, you must also remove related resources such as firewall rules and the gke-oidc-envoy load balancer. The error indicates that the VPC remains in use because the forwarding rule, along with other network resources, wasn’t deleted before Terraform tried to remove the VPC.
Here’s how you can clean them up manually:
gcloud compute firewall-rules list --filter="name:gke-oidc-*"
gcloud compute firewall-rules delete FIREWALL_RULE_NAME
gcloud compute forwarding-rules list --filter="name:gke-oidc-envoy-*"
gcloud compute backend-services list --filter="name:gke-oidc-envoy-*"
gcloud compute addresses list --filter="status:RESERVED"
gcloud compute addresses delete IP_NAME
gcloud compute resources list --filter="name:gke-oidc-*"
If you encounter the same issue when creating a GKE cluster using gcloud, it indicates that the problem is not specific to Terraform but is instead related to how GKE with OIDC provisions and manages resource cleanup.
Here are some steps you can take:
- With the older provider, Terraform might have been automatically managing dependencies differently. The new provider might need explicit dependencies.
- Check if the firewall rules, forwarding rules, and the gke-oidc-envoy resources are properly referenced in Terraform.
- If Terraform isn't handling deletions properly, try manually removing leftover resources before destroying the VPC.
- If Terraform is not correctly recognizing the resources, refresh the state. If any resources are missing, import them and then try to destroy the infrastructure again.
- If the issue started after a provider upgrade, check which versions worked before and compare the changes. If necessary, downgrade the provider version in versions.tf and then reinitialize Terraform.
- After fixing dependencies and cleaning up stale resources, try running again.
If you need further assistance, you can reach out to Google Cloud Support at any time.
Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.
Hi, thanks for the response, alao the load balancer is created as internal instead of external, what are the needs for creating it as external, because the cluster is having a public ip
To create the gke-oidc-envoy load balancer as external instead of internal, you’ll need to modify how GKE deploys the OIDC authentication components. By default, Google Cloud creates an internal load balancer for OIDC, but you can override this by modifying the service settings or manually configuring an external LoadBalancer.
kubectl get service gke-oidc-envoy -n kube-system -o yaml
gcloud compute firewall-rules list --filter="name:gke-oidc-*"
Modify the firewall rule to allow public access to the load balancer:
gcloud compute firewall-rules update FIREWALL_RULE_NAME --allow tcp:443 --source-ranges=0.0.0.0/0
Or, if needed, create a new rule:
gcloud compute firewall-rules create allow-external-oidc \
--network=YOUR_NETWORK_NAME \
--allow tcp:443 \
--source-ranges=0.0.0.0/0 \
--target-tags=gke-oidc-envoy
kubectl get svc gke-oidc-envoy -n kube-system
export OIDC_EXTERNAL_IP=$(kubectl get svc gke-oidc-envoy -n kube-system -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo "External OIDC Load Balancer IP: $OIDC_EXTERNAL_IP"
To expose gke-oidc-envoy externally, remove the internal load balancer annotation, set the service type to LoadBalancer, and ensure firewall rules allow public access.
If you need further assistance, you can reach out to Google Cloud Support at any time.
Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.