cloudflare-docs
cloudflare-docs copied to clipboard
Deploying a tunnel with terraform and connecting manually
Existing documentation URL(s)
- https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/get-started/create-remote-tunnel/
- https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/deploy-tunnels/deployment-guides/terraform/
What changes are you suggesting?
There's the 2 above mentioned documents on how to create the Cloudflare tunnels in different ways:
- manually via the dashboard,
- with terraform.
I was dealing with a use case that is a combo of both:
- created a tunnel with terraform,
- and manually ran a Mac OS connector with
cloudflared tunnel run
None of the docs cover this use case and quite some time was spent on how to make it work. Which roughly resulted in
- describe the tunnel in Terraform based on: https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/deploy-tunnels/deployment-guides/terraform/
- but now I can't use something like
// Configures the VM to run a startup script that takes in the Terraform variables.
metadata_startup_script = templatefile("./install-tunnel.tpl",
{
tunnel_token = cloudflare_tunnel.auto_tunnel.tunnel_token
})
cloudflared:
image: cloudflare/cloudflared:latest
restart: always
container_name: cloudflared
command: tunnel run --token ${tunnel_token}
since my Mac OS machine is not managed by Terraform.
- Then on Mac OS I had to do:
cloudflared login
cloudflared tunnel token --cred-file ~/.cloudflared/$TUNNEL_ID.json $TUNNEL_ID
cloudflared tunnel run
Quite simple but this command took me some time to find: cloudflared tunnel token --cred-file.
Do you think it would be worth expanding the docs?
Additional information
No response