A way to keep machine name after rebuild

We have a number of VM’s running on AWS. The VM’s are configured entirely by a script that runs on startup. If an issue is detected, or we have to make a major change to a system, the VM is destroyed and setup again. A disk is attached that’s persistent and stores all the data along with any sort of persistent configuration files like SSL certs, Docker stuff, so on.

When the server reloads it comes up with a new machine name (expected). To deal with this I moved the Tailscale data folder that contains the tailscale.state file to the persistent drive and altered the tailscale.service file to point to this location instead. For example

ExecStart=/usr/sbin/tailscaled --state=/opt/etl/tailscale/tailscaled.state --socket=/run/tailscale/tailscaled.sock --port $PORT $FLAGS

The service is then started with an authkey. I had hoped keeping this state file would mean that the machine name would update, but it just creates a new device in the Tailscale portal. Does anyone have any insight on how I could accomplish this?

I think that the tailscaled.state file contains the credentials for that machine and will carry over if transferred (correct me if I’m wrong here). So maybe you dont need to start with an auth key and just start it up to see if it pulls in the credentials from the backed up tailscaled.state file?