tailscale-policy: filter tailscale_devices list by FQDN prefix instead of hostname lookup #138

Closed
opened 2026-05-26 18:03:40 +00:00 by coilysiren · 0 comments
Owner

Problem

After fixing the tailscale_device lookup to use hostname instead of name (coilysiren/infrastructure#137), the two Windows machines still fail import:

could not find device withhostname="kai-desktop-tower"
could not find device withhostname="kai-windows-laptop"

tailscale status --json reveals why:

  • kai-desktop-tower reports OS hostname KAI-DESKTOP-TOWER
  • kai-windows-laptop reports OS hostname LAPTOP-5RANHQD2 (default Windows naming - never renamed in OS)
  • kais-macbook-pro reports OS hostname Kai's MacBook Pro (the Mac initial-setup display name, with apostrophe)
  • kai-server reports KAI-SERVER

Neither name (FQDN) nor hostname (raw OS hostname) is stable enough to key off in devices.yaml. The only stable identifier mapping cleanly to "what Kai calls this machine" is the MagicDNS short prefix of the FQDN (e.g. kai-server. in kai-server.tail09a41b.ts.net).

Change

Drop the per-device tailscale_device lookup. Use tailscale_devices (plural, lists every device on the tailnet) once, then compute the short -> id map in HCL by filtering on startswith(d.name, "${short}.").

This is provider-side: no SSM cache, no per-device pre-resolve, no committed device IDs. The full list is one API call, cached for the lifetime of the plan/apply.

Filed by Claude.

**Problem** After fixing the `tailscale_device` lookup to use `hostname` instead of `name` (coilysiren/infrastructure#137), the two Windows machines still fail import: ``` could not find device withhostname="kai-desktop-tower" could not find device withhostname="kai-windows-laptop" ``` `tailscale status --json` reveals why: - `kai-desktop-tower` reports OS hostname `KAI-DESKTOP-TOWER` - `kai-windows-laptop` reports OS hostname `LAPTOP-5RANHQD2` (default Windows naming - never renamed in OS) - `kais-macbook-pro` reports OS hostname `Kai's MacBook Pro` (the Mac initial-setup display name, with apostrophe) - `kai-server` reports `KAI-SERVER` Neither `name` (FQDN) nor `hostname` (raw OS hostname) is stable enough to key off in `devices.yaml`. The only stable identifier mapping cleanly to "what Kai calls this machine" is the **MagicDNS short prefix** of the FQDN (e.g. `kai-server.` in `kai-server.tail09a41b.ts.net`). **Change** Drop the per-device `tailscale_device` lookup. Use `tailscale_devices` (plural, lists every device on the tailnet) once, then compute the `short -> id` map in HCL by filtering on `startswith(d.name, "${short}.")`. This is provider-side: no SSM cache, no per-device pre-resolve, no committed device IDs. The full list is one API call, cached for the lifetime of the plan/apply. Filed by Claude.
Sign in to join this conversation.
No description provided.