Skip to content

Handle Missing Devices and Enforce Recreation on device_id Change for tailscale_device_subnet_routes #527

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tailscale/resource_device_subnet_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func resourceDeviceSubnetRoutes() *schema.Resource {
Type: schema.TypeString,
Required: true,
Description: "The device to set subnet routes for",
ForceNew: true,
},
"routes": {
Type: schema.TypeSet,
Expand All @@ -62,7 +63,14 @@ func resourceDeviceSubnetRoutesRead(ctx context.Context, d *schema.ResourceData,
deviceID := d.Get("device_id").(string)

routes, err := client.Devices().SubnetRoutes(ctx, deviceID)

if err != nil {
// If the device is not found, remove from the state so we can create it again.
if tailscale.IsNotFound(err) {
d.SetId("")
return nil
}

return diagnosticsError(err, "Failed to fetch device subnet routes")
}

Expand Down