Skip to content

Commit

Permalink
tailscale: use V2 client for device authorization
Browse files Browse the repository at this point in the history
Updates tailscale/corp#21867

Signed-off-by: Percy Wegmann <percy@tailscale.com>
  • Loading branch information
oxtoacart committed Aug 2, 2024
1 parent a23585a commit 1b25109
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ require (
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0
github.com/stretchr/testify v1.9.0
github.com/tailscale/hujson v0.0.0-20221223112325-20486734a56a
<<<<<<< HEAD
github.com/tailscale/tailscale-client-go v1.17.1-0.20240729175651-90a1e935cc19
github.com/tailscale/tailscale-client-go/v2 v2.0.0-20240801195603-6096900af9df
=======
github.com/tailscale/tailscale-client-go v1.17.0
github.com/tailscale/tailscale-client-go/v2 v2.0.0-20240801205641-d930be734670
>>>>>>> bfc4a29 (tailscale: use V2 client for device authorization)
golang.org/x/tools v0.23.0
tailscale.com v1.70.0
)
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,17 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tailscale/hujson v0.0.0-20221223112325-20486734a56a h1:SJy1Pu0eH1C29XwJucQo73FrleVK6t4kYz4NVhp34Yw=
github.com/tailscale/hujson v0.0.0-20221223112325-20486734a56a/go.mod h1:DFSS3NAGHthKo1gTlmEcSBiZrRJXi28rLNd/1udP1c8=
<<<<<<< HEAD
github.com/tailscale/tailscale-client-go v1.17.1-0.20240729175651-90a1e935cc19 h1:fRLv1yZH1ueL1cnpLhOnOymoBfMCIviCn0e0VkAjkK4=
github.com/tailscale/tailscale-client-go v1.17.1-0.20240729175651-90a1e935cc19/go.mod h1:jbwJyHniK3nyLttwcDTXnfdDQEnADvc4VMOP8hZWnR0=
github.com/tailscale/tailscale-client-go/v2 v2.0.0-20240801195603-6096900af9df h1:XjHI0pFxhttM1nEn/WNGOO3wrJYEJSZarJm0i5WFXgY=
github.com/tailscale/tailscale-client-go/v2 v2.0.0-20240801195603-6096900af9df/go.mod h1:i/MSgQ71kdyh1Wdp50XxrIgtsyO4uZ2SZSPd83lGKHM=
=======
github.com/tailscale/tailscale-client-go v1.17.0 h1:4ZTsfB2hiiiIcx7prcXapZHO5K+TXB5fTdhGxdKGR88=
github.com/tailscale/tailscale-client-go v1.17.0/go.mod h1:Zxz9AWl4cNX8F+jE7iIeo6Me7dGPXNdCFIoVeovH6eI=
github.com/tailscale/tailscale-client-go/v2 v2.0.0-20240801205641-d930be734670 h1:Gh7C7H9uAmjeCMxDtYTP3GCY2OtMDzPLVQlTJQOGSL4=
github.com/tailscale/tailscale-client-go/v2 v2.0.0-20240801205641-d930be734670/go.mod h1:i/MSgQ71kdyh1Wdp50XxrIgtsyO4uZ2SZSPd83lGKHM=
>>>>>>> bfc4a29 (tailscale: use V2 client for device authorization)
github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
Expand Down
12 changes: 6 additions & 6 deletions tailscale/resource_device_authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/tailscale/tailscale-client-go/tailscale"
"github.com/tailscale/tailscale-client-go/v2"
)

func resourceDeviceAuthorization() *schema.Resource {
Expand All @@ -32,10 +32,10 @@ func resourceDeviceAuthorization() *schema.Resource {
}

func resourceDeviceAuthorizationRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
client := m.(*Clients).V1
client := m.(*Clients).V2
deviceID := d.Get("device_id").(string)

devices, err := client.Devices(ctx)
devices, err := client.Devices().List(ctx)
if err != nil {
return diagnosticsError(err, "Failed to fetch devices")
}
Expand Down Expand Up @@ -75,10 +75,10 @@ func resourceDeviceAuthorizationCreate(ctx context.Context, d *schema.ResourceDa
}

func resourceDeviceAuthorizationUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
client := m.(*Clients).V1
client := m.(*Clients).V2
deviceID := d.Get("device_id").(string)

devices, err := client.Devices(ctx)
devices, err := client.Devices().List(ctx)
if err != nil {
return diagnosticsError(err, "Failed to fetch devices")
}
Expand All @@ -104,7 +104,7 @@ func resourceDeviceAuthorizationUpdate(ctx context.Context, d *schema.ResourceDa
return nil
}

if err = client.AuthorizeDevice(ctx, deviceID); err != nil {
if err = client.Devices().SetAuthorized(ctx, deviceID, true); err != nil {
return diagnosticsError(err, "Failed to authorize device")
}

Expand Down

0 comments on commit 1b25109

Please sign in to comment.