Cannot delete tunnel because it has active connections | Terraform

Hello! I currently use Cloudflare tunnels to expose internal applications to the developers. Dashboards, DB GUI, etc.

As our applications are running in Kubernetes, I use the Crossplane Terraform provider to deploy the tunnel using Terraform along their application helm charts.

On the terraform workspace deletion, I encounter the following issue:

cannot destroy Terraform configuration: Terraform encountered an error. 
Summary: error deleting tunnel config "9xx21xxa-xxxx-xxxx-xxxx-xxxxxxxxxx": Cannot delete tunnel because it has active connections. Close any cloudflareds running the tunnel, or run `cloudflared tunnel cleanup` to delete stale connections, then try to delete it again. (1022). 


It appears when the cloudflared pod stopped already. (so there shouldn't be any connections left)

So here is what I tried, without success:

  • Delete the
    cloudflared
    pod first, before cleaning up the TF workspace.
  • Clean up the TF workspace first, then delete the pod.
  • Add a lifecycle.preStop hook to my cloudflare pod, running the command cloudflared tunnel cleanup TUNNEL_NAME.
I am running out of ideas...
Was this page helpful?