Closed kim-anchorzero closed 2 months ago
Thank you for reporting this @kim-anchorzero!
As a clarifying question: in your above example after applying the configuration the first time are you also enabling / allowing the exit node from the admin console, or is that something you are only seeing / having to do after the second apply?
Having a device act as an exit node or subnet router is a two-step process that requires both advertising the routes , which is done exclusively via the CLI, and enabling the advertised routes, which can be done via a number of methods including the tailscale_device_subnet_routes
resource or through the admin console as mentioned above.
The tailscale_device_subnet_routes
deals exclusively with enabling routes and must be done in conjunction with the --advertise-exit-node
or --advertise-routes
flags. Enabling routes and exit nodes via the admin console (or autoApprovers if enabled) will enable these outside of Terraform state and cause the drift that you are seeing.
Our documentation for this resource is definitely sparse, I'll look at adding more clarification around the above / specifying more clearly what this resource is actually doing.
We have auto approvers set up up for the device's tags and it works properly (automatically) on first attempt. Additionally, if I use the tailscale_device_subnet_routes workaround mentioned above it will never lose permission.
Gotcha! This is definitely a rough / awkward edge with using auto approvers in the ACL in combination with the tailscale_device_subnet_routes
resource as I think there is contention between the two in tracking the state of the enabled routes.
Adding the "0.0.0.0/0"
and "::/0"
routes to the tailscale_device_subnet_routes
is the correct path forward here from the Terraform perspective in preventing this drift and preventing the permission loss.
Hey @kim-anchorzero , apologies for the long tail on improving the documentation for this! We've released v0.17.0 of the Terraform provider which has a (hopefully) clearer explanation of the usage / gotchas around using the resource (see here).
We've also updated the API documentation for the associated endpoint to hopefully be clearer.
Describe the bug If you advertise a node via
--advertise-exit-node
in a terraform template that also definesresource "tailscale_device_subnet_routes"
it will work on first launch but on second terraform run you will see a change such as:If applied the node will stop functioning as an exit node, being listed as requiring approval in the UI. If that permission is granted it will once again function.
To Reproduce Steps to reproduce the behaviour:
TAILSCALE_UP_ARGS
contains--advertise-exit-node
tailscale_device_subnet_routes
resource that defines some block of routes but not the exit node routesExpected behaviour The functionality of the exit node is not impacted via subsequent terraform runs.
Desktop (please complete the following information):
Additional context The following (untested, likely incomplete) template should demonstrate the issue:
Note that if you explicitly add the exit node routes to the
tailscale_device_subnet_routes
block this issue doesn't happen. This lines up with the documentation for https://registry.terraform.io/providers/tailscale/tailscale/latest/docs/resources/device_subnet_routes which suggests these routes are how you should advertise an exit node - it's just somewhat surprising that doing so via the CLI args can have these unpredictable results.