From bfc4a293a909bbf62e85ba3eb77861fc62d304ac Mon Sep 17 00:00:00 2001 From: Percy Wegmann Date: Thu, 1 Aug 2024 15:59:06 -0500 Subject: [PATCH] tailscale: use V2 client for device authorization Updates tailscale/corp#21867 Signed-off-by: Percy Wegmann --- go.mod | 2 +- go.sum | 8 ++------ tailscale/resource_device_authorization.go | 12 ++++++------ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index f1266126..25f46984 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/stretchr/testify v1.9.0 github.com/tailscale/hujson v0.0.0-20221223112325-20486734a56a github.com/tailscale/tailscale-client-go v1.17.0 + github.com/tailscale/tailscale-client-go/v2 v2.0.0-20240801205641-d930be734670 golang.org/x/tools v0.23.0 tailscale.com v1.70.0 ) @@ -66,7 +67,6 @@ require ( github.com/rivo/uniseg v0.4.4 // indirect github.com/shopspring/decimal v1.3.1 // indirect github.com/spf13/cast v1.6.0 // indirect - github.com/tailscale/tailscale-client-go/v2 v2.0.0-20240801195603-6096900af9df // indirect github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect diff --git a/go.sum b/go.sum index daaf523f..86c518e4 100644 --- a/go.sum +++ b/go.sum @@ -190,10 +190,8 @@ github.com/tailscale/hujson v0.0.0-20221223112325-20486734a56a h1:SJy1Pu0eH1C29X github.com/tailscale/hujson v0.0.0-20221223112325-20486734a56a/go.mod h1:DFSS3NAGHthKo1gTlmEcSBiZrRJXi28rLNd/1udP1c8= 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-20240801180637-13cd305a6872 h1:03dMmOLXZ6UKnFsmvtka3npfO09kaj3fOiE9RKCop0c= -github.com/tailscale/tailscale-client-go/v2 v2.0.0-20240801180637-13cd305a6872/go.mod h1:i/MSgQ71kdyh1Wdp50XxrIgtsyO4uZ2SZSPd83lGKHM= -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/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= 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= @@ -235,8 +233,6 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= -golang.org/x/oauth2 v0.19.0 h1:9+E/EZBCbTLNrbN35fHv/a/d/mOBatymz1zbtQrXpIg= -golang.org/x/oauth2 v0.19.0/go.mod h1:vYi7skDa1x015PmRRYZ7+s1cWyPgrPiSYRe4rnsexc8= golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/tailscale/resource_device_authorization.go b/tailscale/resource_device_authorization.go index cf0d2c40..17c0064a 100644 --- a/tailscale/resource_device_authorization.go +++ b/tailscale/resource_device_authorization.go @@ -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 { @@ -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") } @@ -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") } @@ -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") }