-
Notifications
You must be signed in to change notification settings - Fork 47
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
FR: add ability to delete devices #68
Comments
Hey @rsyring, so deleting a device is a little bit complicated when it comes to the terraform provider, as devices cannot be created using it. A terraform provider typically describes the lifecycle of a resource, but a device cannot be a resource because it can't be created purely via API calls. One suggestion might be that when the |
I managed to get a POC for this working on my branch but I must say I don't love the solution either. As @davidsbond said, devices cannot be created using it, so the provider has to track the changes that are happening elsewhere. I made the create part of the provider ignore if the device isn't present, effectively giving it an "unavailable" marker. Whenever terraform runs and finds the device created, it will update its state with the correct ID. When the resource is deleted, it will be cleaned up using the device delete method. provider "tailscale" {
# api_key = "my-api-key"
# tailnet = "my-tailnet"
}
resource "tailscale_device" "example" {
name = "example.my-tailnet"
} If you want, I can submit a PR for it. |
@pellegrino personally, I don't think this is a good way to go, if we can't actually create the device via API calls we shouldn't provide a resource for it. I'd be willing to consider deletion occurring from deleting a For now my recommendation would be to use an ephemeral key that will remove the resource once the workload dies or restarts |
Just making the implicit explicit: we have a chicken and egg problem here between Tailscale's operational model and Terraform's. Since the models are currently incompatible, some kind of workaround is going to be needed. FWIW, I like the idea of a provider even though it can't actually create the record. Could take the "wait_for" logic from #72 and apply it here as well. Put BIG WARNINGS in the docs that the device isn't actually created through the API and point to an example of how to get Tailscale installed and running on a new host at creation time. Could also add the warning and explanation to the error message, and a link to the docs, if the provider times out waiting for the Tailscale device to come online. While I agree that this violates the spirit of what a provider is in this case, the implementation feels closer to what is "should be" and if Tailscale ever gives the ability to actually create the resource through the API, only the provider implementation would change. The terraform scripts would continue to work as-is, with potentially a deprecation notice in case they set the Having said all that, I wouldn't mind deleting through |
I have a similar use case as @rsyring. Deleting the device through Using ephemeral key does not really fit since we install VMs (also terraform managed) that tend to reboot sometimes. |
This workaround seems ok, we delete any existing devices in a remote-exec provisioner while creating a VM (openstack + ubuntu 22.04 for my case), with the appropriately defined vars for the keys.
|
A behaviour that maps onto existing Terraform workflows and resource lifecycles would be to: delete all machines using a key created through |
I've been trying to think of a way to handle this and I just can't think of a clean solution as it stand right now. I really think it needs an architectural change from Tailscale, like @mlangenberg mentioned in #232 Tailscale needs the ability to create a one time use key that associates a nodeId. Once that's possible you can have a |
Hey Tailscale team, any updates on this one? |
@davidsbond How amenable would you be towards allowing exposure of the provider's internally generated apiKey via a provider function, for use in cases like these? I could write a few pages about how there are absolutely no valid options for handling common terraform usecases with the current design without massive security AND convenience compromises. (Pass around a static apikey in the only-encrypted-at-rest terraform state and write extra mechanisms to try to check when it's out of date and manually recreate it every few months? No thanks.) But as you can likely already tell; I am rather frustrated, and so I think it's not the best idea. There are about a dozen better solutions to this than what I am suggesting above, but all the obvious ones have already been rejected by tailscale devs in different threads across different repos. The API could leverage the identity of the node it is run from for authentication. Logout could actually allow re-use of a name. A flag could be added to Supporting extremely basic usage patterns should probably come before design-purity-idealism; but that's just my opinion. My apologies for the rudeness. |
This is already supported. Use
This is also already supported - use an oauth client secret and specify |
Is your feature request related to a problem? Please describe.
When destroying resources with terraform, I'd like the ability to remove the device from Tailscale. For example, when an AWS instance will be deleted, I want it's associated tailscale device to also be deleted.
Describe the solution you'd like
Keep track of devices in Terraform state and, when the device is removed, use the DELETE device API to remove the device from the tailnet.
The text was updated successfully, but these errors were encountered: