diff --git a/docs/resources/device_key.md b/docs/resources/device_key.md index 509ec070..f3bb1c0f 100644 --- a/docs/resources/device_key.md +++ b/docs/resources/device_key.md @@ -37,3 +37,12 @@ resource "tailscale_device_key" "example_key" { ### Read-Only - `id` (String) The ID of this resource. + +## Import + +Import is supported using the following syntax: + +```shell +# Device key can be imported using the device id, e.g., +terraform import tailscale_device_key.sample 123456789 +``` diff --git a/docs/resources/device_subnet_routes.md b/docs/resources/device_subnet_routes.md index 78703516..77948184 100644 --- a/docs/resources/device_subnet_routes.md +++ b/docs/resources/device_subnet_routes.md @@ -53,3 +53,12 @@ resource "tailscale_device_subnet_routes" "sample_exit_node" { ### Read-Only - `id` (String) The ID of this resource. + +## Import + +Import is supported using the following syntax: + +```shell +# Device subnet rules can be imported using the device id, e.g., +terraform import tailscale_device_subnet_routes.sample 123456789 +``` diff --git a/docs/resources/device_tags.md b/docs/resources/device_tags.md index 6837d28b..2beb14aa 100644 --- a/docs/resources/device_tags.md +++ b/docs/resources/device_tags.md @@ -34,3 +34,12 @@ resource "tailscale_device_tags" "sample_tags" { ### Read-Only - `id` (String) The ID of this resource. + +## Import + +Import is supported using the following syntax: + +```shell +# Device tags can be imported using the device id, e.g., +terraform import tailscale_device_tags.sample 123456789 +``` diff --git a/docs/resources/dns_nameservers.md b/docs/resources/dns_nameservers.md index 62f2a2ff..4810d66b 100644 --- a/docs/resources/dns_nameservers.md +++ b/docs/resources/dns_nameservers.md @@ -31,3 +31,12 @@ resource "tailscale_dns_nameservers" "sample_nameservers" { ### Read-Only - `id` (String) The ID of this resource. + +## Import + +Import is supported using the following syntax: + +```shell +# ID doesn't matter. +terraform import tailscale_dns_nameservers.sample dns_nameservers +``` diff --git a/docs/resources/dns_search_paths.md b/docs/resources/dns_search_paths.md index 40ec9af6..277e58bf 100644 --- a/docs/resources/dns_search_paths.md +++ b/docs/resources/dns_search_paths.md @@ -30,3 +30,12 @@ resource "tailscale_dns_search_paths" "sample_search_paths" { ### Read-Only - `id` (String) The ID of this resource. + +## Import + +Import is supported using the following syntax: + +```shell +# ID doesn't matter. +terraform import tailscale_dns_search_paths.sample dns_search_paths +``` diff --git a/examples/resources/tailscale_device_key/import.sh b/examples/resources/tailscale_device_key/import.sh new file mode 100644 index 00000000..d8eba9a5 --- /dev/null +++ b/examples/resources/tailscale_device_key/import.sh @@ -0,0 +1,2 @@ +# Device key can be imported using the device id, e.g., +terraform import tailscale_device_key.sample 123456789 diff --git a/examples/resources/tailscale_device_subnet_routes/import.sh b/examples/resources/tailscale_device_subnet_routes/import.sh new file mode 100644 index 00000000..5e9e2459 --- /dev/null +++ b/examples/resources/tailscale_device_subnet_routes/import.sh @@ -0,0 +1,2 @@ +# Device subnet rules can be imported using the device id, e.g., +terraform import tailscale_device_subnet_routes.sample 123456789 diff --git a/examples/resources/tailscale_device_tags/import.sh b/examples/resources/tailscale_device_tags/import.sh new file mode 100644 index 00000000..60403234 --- /dev/null +++ b/examples/resources/tailscale_device_tags/import.sh @@ -0,0 +1,2 @@ +# Device tags can be imported using the device id, e.g., +terraform import tailscale_device_tags.sample 123456789 diff --git a/examples/resources/tailscale_dns_nameservers/import.sh b/examples/resources/tailscale_dns_nameservers/import.sh new file mode 100644 index 00000000..ea17c959 --- /dev/null +++ b/examples/resources/tailscale_dns_nameservers/import.sh @@ -0,0 +1,2 @@ +# ID doesn't matter. +terraform import tailscale_dns_nameservers.sample dns_nameservers diff --git a/examples/resources/tailscale_dns_search_paths/import.sh b/examples/resources/tailscale_dns_search_paths/import.sh new file mode 100644 index 00000000..99d40861 --- /dev/null +++ b/examples/resources/tailscale_dns_search_paths/import.sh @@ -0,0 +1,2 @@ +# ID doesn't matter. +terraform import tailscale_dns_search_paths.sample dns_search_paths diff --git a/tailscale/resource_device_key.go b/tailscale/resource_device_key.go index bb260cad..2b6c457a 100644 --- a/tailscale/resource_device_key.go +++ b/tailscale/resource_device_key.go @@ -19,6 +19,9 @@ func resourceDeviceKey() *schema.Resource { CreateContext: resourceDeviceKeyCreate, DeleteContext: resourceDeviceKeyDelete, UpdateContext: resourceDeviceKeyUpdate, + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, Schema: map[string]*schema.Schema{ "device_id": { Type: schema.TypeString, @@ -67,13 +70,14 @@ func resourceDeviceKeyDelete(ctx context.Context, d *schema.ResourceData, m inte func resourceDeviceKeyRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*tsclient.Client) - deviceID := d.Get("device_id").(string) + deviceID := d.Id() device, err := client.Devices().Get(ctx, deviceID) if err != nil { return diagnosticsError(err, "Failed to fetch devices") } + d.Set("device_id", device.ID) if err = d.Set("key_expiry_disabled", device.KeyExpiryDisabled); err != nil { return diagnosticsError(err, "failed to set key_expiry_disabled field") } diff --git a/tailscale/resource_device_subnet_routes.go b/tailscale/resource_device_subnet_routes.go index 4eca199e..efecf752 100644 --- a/tailscale/resource_device_subnet_routes.go +++ b/tailscale/resource_device_subnet_routes.go @@ -26,6 +26,9 @@ func resourceDeviceSubnetRoutes() *schema.Resource { CreateContext: resourceDeviceSubnetRoutesCreate, UpdateContext: resourceDeviceSubnetRoutesUpdate, DeleteContext: resourceDeviceSubnetRoutesDelete, + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, Schema: map[string]*schema.Schema{ "device_id": { Type: schema.TypeString, @@ -46,13 +49,14 @@ func resourceDeviceSubnetRoutes() *schema.Resource { func resourceDeviceSubnetRoutesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*tsclient.Client) - deviceID := d.Get("device_id").(string) + deviceID := d.Id() routes, err := client.Devices().SubnetRoutes(ctx, deviceID) if err != nil { return diagnosticsError(err, "Failed to fetch device subnet routes") } + d.Set("device_id", deviceID) if err = d.Set("routes", routes.Enabled); err != nil { return diag.FromErr(err) } diff --git a/tailscale/resource_device_tags.go b/tailscale/resource_device_tags.go index 9bd65461..1deeb731 100644 --- a/tailscale/resource_device_tags.go +++ b/tailscale/resource_device_tags.go @@ -30,6 +30,9 @@ func resourceDeviceTags() *schema.Resource { CreateContext: resourceDeviceTagsSet, UpdateContext: resourceDeviceTagsSet, DeleteContext: deleteContext, + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, Schema: map[string]*schema.Schema{ "device_id": { Type: schema.TypeString, @@ -50,14 +53,14 @@ func resourceDeviceTags() *schema.Resource { func resourceDeviceTagsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*tsclient.Client) - deviceID := d.Get("device_id").(string) + deviceID := d.Id() device, err := client.Devices().Get(ctx, deviceID) if err != nil { return diagnosticsError(err, "Failed to fetch device") } - d.SetId(device.ID) + d.Set("device_id", device.ID) d.Set("tags", device.Tags) return nil } diff --git a/tailscale/resource_dns_nameservers.go b/tailscale/resource_dns_nameservers.go index 831c2d90..3cc461ba 100644 --- a/tailscale/resource_dns_nameservers.go +++ b/tailscale/resource_dns_nameservers.go @@ -19,6 +19,9 @@ func resourceDNSNameservers() *schema.Resource { CreateContext: resourceDNSNameserversCreate, UpdateContext: resourceDNSNameserversUpdate, DeleteContext: resourceDNSNameserversDelete, + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, Schema: map[string]*schema.Schema{ "nameservers": { Type: schema.TypeList, diff --git a/tailscale/resource_dns_search_paths.go b/tailscale/resource_dns_search_paths.go index 71c6c865..5ab127e3 100644 --- a/tailscale/resource_dns_search_paths.go +++ b/tailscale/resource_dns_search_paths.go @@ -19,6 +19,9 @@ func resourceDNSSearchPaths() *schema.Resource { UpdateContext: resourceDNSSearchPathsUpdate, DeleteContext: resourceDNSSearchPathsDelete, CreateContext: resourceDNSSearchPathsCreate, + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, Schema: map[string]*schema.Schema{ "search_paths": { Type: schema.TypeList,