Skip to content

Commit 175d359

Browse files
authored
tailscale: add node_id support (#513)
- Add `node_id` to both `tailscale_device` and `tailscale_devices` data sources. This is already exposed by the Go client and something we want to provide to users. - Update docs to indicate that `id` is a legacy identifier and node_id should be preferred. - In `resource_device_authorization.go`, detect if the user passes a node_id into device_id and save it to state instead of the legacy id, this prevents a perpetual diff. - Add backwards-compatibility and node_id tests in `resource_device_authorization_test.go` - In `resource_device_key.go`, detect if the user passes a node_id into device_id and save it to state instead of the legacy id, this prevents a perpetual diff. - Add backwards compatibility and node_id tests in `resource_device_key_test.go` - In `resource_device_tags.go`, detect if the user passes a node_id into device_id and save it to state instead of the legacy id, this prevents a perpetual diff. - Add backwards compatibility and node_id tests in `resource_device_tags_test.go` - Add a test in `resource_device_subnet_routes_test.go` to verify backwards compatibility that `node_id` works as `device_id`. Since we use a UUID for this resource, we don't need to update the read step as with the others. Long term, we will likely want to switch users over to using `node_id` as the resource id, but will want to do that during a major version change. Signed-off-by: Zach Buchheit <[email protected]>
1 parent 09b3b5d commit 175d359

23 files changed

+702
-23
lines changed

docs/data-sources/device.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ data "tailscale_device" "sample_device2" {
3737

3838
- `addresses` (List of String) The list of device's IPs
3939
- `id` (String) The ID of this resource.
40+
- `node_id` (String) The preferred indentifier for a device.
4041
- `tags` (Set of String) The tags applied to the device
4142
- `user` (String) The user associated with the device

docs/data-sources/devices.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ Read-Only:
3939
- `hostname` (String)
4040
- `id` (String)
4141
- `name` (String)
42+
- `node_id` (String)
4243
- `tags` (Set of String)
4344
- `user` (String)

docs/resources/device_authorization.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ data "tailscale_device" "sample_device" {
1818
}
1919
2020
resource "tailscale_device_authorization" "sample_authorization" {
21-
device_id = data.tailscale_device.sample_device.id
21+
# Prefer the new, stable `node_id` attribute; the legacy `.id` field still works.
22+
device_id = data.tailscale_device.sample_device.node_id
2223
authorized = true
2324
}
2425
```
@@ -40,6 +41,8 @@ resource "tailscale_device_authorization" "sample_authorization" {
4041
Import is supported using the following syntax:
4142

4243
```shell
43-
# Device authorization can be imported using the device id, e.g.,
44+
# Device authorization can be imported using the node ID (preferred), e.g.,
45+
terraform import tailscale_device_authorization.sample_authorization nodeidCNTRL
46+
# Device authorization can be imported using the legacy ID, e.g.,
4447
terraform import tailscale_device_authorization.sample_authorization 123456789
4548
```

docs/resources/device_key.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ data "tailscale_device" "example_device" {
1818
}
1919
2020
resource "tailscale_device_key" "example_key" {
21-
device_id = data.tailscale_device.example_device.id
21+
# Prefer the new, stable `node_id` attribute; the legacy `.id` field still works.
22+
device_id = data.tailscale_device.example_device.node_id
2223
key_expiry_disabled = true
2324
}
2425
```
@@ -43,6 +44,8 @@ resource "tailscale_device_key" "example_key" {
4344
Import is supported using the following syntax:
4445

4546
```shell
46-
# Device key can be imported using the device id, e.g.,
47+
# Device key can be imported using the node ID (preferred), e.g.,
48+
terraform import tailscale_device_key.sample nodeidCNTRL
49+
# Device key can be imported using the legacy ID, e.g.,
4750
terraform import tailscale_device_key.sample 123456789
4851
```

docs/resources/device_subnet_routes.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ data "tailscale_device" "sample_device" {
2424
}
2525
2626
resource "tailscale_device_subnet_routes" "sample_routes" {
27-
device_id = data.tailscale_device.sample_device.id
27+
# Prefer the new, stable `node_id` attribute; the legacy `.id` field still works.
28+
device_id = data.tailscale_device.sample_device.node_id
2829
routes = [
2930
"10.0.1.0/24",
3031
"1.2.0.0/16",
@@ -33,7 +34,8 @@ resource "tailscale_device_subnet_routes" "sample_routes" {
3334
}
3435
3536
resource "tailscale_device_subnet_routes" "sample_exit_node" {
36-
device_id = data.tailscale_device.sample_device.id
37+
# Prefer the new, stable `node_id` attribute; the legacy `.id` field still works.
38+
device_id = data.tailscale_device.sample_device.node_id
3739
routes = [
3840
# Configure as an exit node
3941
"0.0.0.0/0",
@@ -59,6 +61,8 @@ resource "tailscale_device_subnet_routes" "sample_exit_node" {
5961
Import is supported using the following syntax:
6062

6163
```shell
62-
# Device subnet rules can be imported using the device id, e.g.,
64+
# Device subnet rules can be imported using the node ID (preferred), e.g.,
65+
terraform import tailscale_device_subnet_routes.sample nodeidCNTRL
66+
# Device subnet rules can be imported using the legacy ID, e.g.,
6367
terraform import tailscale_device_subnet_routes.sample 123456789
6468
```

docs/resources/device_tags.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ data "tailscale_device" "sample_device" {
1818
}
1919
2020
resource "tailscale_device_tags" "sample_tags" {
21-
device_id = data.tailscale_device.sample_device.id
21+
# Prefer the new, stable `node_id` attribute; the legacy `.id` field still works.
22+
device_id = data.tailscale_device.sample_device.node_id
2223
tags = ["room:bedroom"]
2324
}
2425
```
@@ -40,6 +41,8 @@ resource "tailscale_device_tags" "sample_tags" {
4041
Import is supported using the following syntax:
4142

4243
```shell
43-
# Device tags can be imported using the device id, e.g.,
44+
# Device tags can be imported using the node ID (preferred), e.g.,
45+
terraform import tailscale_device_tags.sample nodeidCNTRL
46+
# Device tags can be imported using the legacy ID, e.g.,
4447
terraform import tailscale_device_tags.sample 123456789
4548
```
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
# Device authorization can be imported using the device id, e.g.,
1+
# Device authorization can be imported using the node ID (preferred), e.g.,
2+
terraform import tailscale_device_authorization.sample_authorization nodeidCNTRL
3+
# Device authorization can be imported using the legacy ID, e.g.,
24
terraform import tailscale_device_authorization.sample_authorization 123456789

examples/resources/tailscale_device_authorization/resource.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ data "tailscale_device" "sample_device" {
33
}
44

55
resource "tailscale_device_authorization" "sample_authorization" {
6-
device_id = data.tailscale_device.sample_device.id
6+
# Prefer the new, stable `node_id` attribute; the legacy `.id` field still works.
7+
device_id = data.tailscale_device.sample_device.node_id
78
authorized = true
89
}
910

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
# Device key can be imported using the device id, e.g.,
1+
# Device key can be imported using the node ID (preferred), e.g.,
2+
terraform import tailscale_device_key.sample nodeidCNTRL
3+
# Device key can be imported using the legacy ID, e.g.,
24
terraform import tailscale_device_key.sample 123456789

examples/resources/tailscale_device_key/resource.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ data "tailscale_device" "example_device" {
33
}
44

55
resource "tailscale_device_key" "example_key" {
6-
device_id = data.tailscale_device.example_device.id
6+
# Prefer the new, stable `node_id` attribute; the legacy `.id` field still works.
7+
device_id = data.tailscale_device.example_device.node_id
78
key_expiry_disabled = true
89
}

0 commit comments

Comments
 (0)