Skip to content

Commit a6ac885

Browse files
committed
resource_device_subnet_routes: handle 404 response from resourceDeviceSubnetRoutesRead
Reset resource id to force recreation when resourceDeviceSubnetRoutesRead receives a 404 status code Fixes #526 Signed-off-by: Brendan Dalpe <[email protected]>
1 parent 8b2932c commit a6ac885

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

tailscale/resource_device_subnet_routes.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func resourceDeviceSubnetRoutes() *schema.Resource {
4444
Type: schema.TypeString,
4545
Required: true,
4646
Description: "The device to set subnet routes for",
47+
ForceNew: true,
4748
},
4849
"routes": {
4950
Type: schema.TypeSet,
@@ -62,7 +63,14 @@ func resourceDeviceSubnetRoutesRead(ctx context.Context, d *schema.ResourceData,
6263
deviceID := d.Get("device_id").(string)
6364

6465
routes, err := client.Devices().SubnetRoutes(ctx, deviceID)
66+
6567
if err != nil {
68+
// If the device is not found, remove from the state so we can create it again.
69+
if tailscale.IsNotFound(err) {
70+
d.SetId("")
71+
return nil
72+
}
73+
6674
return diagnosticsError(err, "Failed to fetch device subnet routes")
6775
}
6876

0 commit comments

Comments
 (0)