Skip to content

Commit

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

Signed-off-by: Percy Wegmann <[email protected]>
  • Loading branch information
oxtoacart committed Aug 3, 2024
1 parent 904da9e commit 886dcc0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +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.1-0.20240729175651-90a1e935cc19
github.com/tailscale/tailscale-client-go/v2 v2.0.0-20240801195603-6096900af9df
github.com/tailscale/tailscale-client-go/v2 v2.0.0-20240803191425-356bbf0acf8b
golang.org/x/tools v0.23.0
tailscale.com v1.70.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +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.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/v2 v2.0.0-20240803191425-356bbf0acf8b h1:soSBC5BTAxR7SVC3IukK3aJezkhyFZJqUn43Yo01TMk=
github.com/tailscale/tailscale-client-go/v2 v2.0.0-20240803191425-356bbf0acf8b/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=
Expand Down
18 changes: 9 additions & 9 deletions tailscale/resource_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"

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

func resourceWebhook() *schema.Resource {
Expand Down Expand Up @@ -83,7 +83,7 @@ func resourceWebhook() *schema.Resource {
}

func resourceWebhookCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
client := m.(*Clients).V1
client := m.(*Clients).V2

endpointURL := d.Get("endpoint_url").(string)
providerType := tailscale.WebhookProviderType(d.Get("provider_type").(string))
Expand All @@ -100,7 +100,7 @@ func resourceWebhookCreate(ctx context.Context, d *schema.ResourceData, m interf
Subscriptions: requestSubscriptions,
}

webhook, err := client.CreateWebhook(ctx, request)
webhook, err := client.Webhooks().Create(ctx, request)
if err != nil {
return diagnosticsError(err, "Failed to create webhook")
}
Expand All @@ -113,9 +113,9 @@ func resourceWebhookCreate(ctx context.Context, d *schema.ResourceData, m interf
}

func resourceWebhookRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
client := m.(*Clients).V1
client := m.(*Clients).V2

webhook, err := client.Webhook(ctx, d.Id())
webhook, err := client.Webhooks().Get(ctx, d.Id())
if err != nil {
return diagnosticsError(err, "Failed to fetch webhook")
}
Expand Down Expand Up @@ -144,15 +144,15 @@ func resourceWebhookUpdate(ctx context.Context, d *schema.ResourceData, m interf
return resourceWebhookRead(ctx, d, m)
}

client := m.(*Clients).V1
client := m.(*Clients).V2
subscriptions := d.Get("subscriptions").(*schema.Set).List()

var requestSubscriptions []tailscale.WebhookSubscriptionType
for _, subscription := range subscriptions {
requestSubscriptions = append(requestSubscriptions, tailscale.WebhookSubscriptionType(subscription.(string)))
}

_, err := client.UpdateWebhook(ctx, d.Id(), requestSubscriptions)
_, err := client.Webhooks().Update(ctx, d.Id(), requestSubscriptions)
if err != nil {
return diagnosticsError(err, "Failed to update webhook")
}
Expand All @@ -161,9 +161,9 @@ func resourceWebhookUpdate(ctx context.Context, d *schema.ResourceData, m interf
}

func resourceWebhookDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
client := m.(*Clients).V1
client := m.(*Clients).V2

err := client.DeleteWebhook(ctx, d.Id())
err := client.Webhooks().Delete(ctx, d.Id())
if err != nil {
return diagnosticsError(err, "Failed to delete webhook")
}
Expand Down
10 changes: 5 additions & 5 deletions tailscale/resource_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

tsclient "github.com/tailscale/tailscale-client-go/tailscale"
tsclient "github.com/tailscale/tailscale-client-go/v2"
"github.com/tailscale/terraform-provider-tailscale/tailscale"
)

Expand Down Expand Up @@ -130,8 +130,8 @@ func testAccCheckWebhookExists(resourceName string, webhook *tsclient.Webhook) r
return fmt.Errorf("resource has no ID set")
}

client := testAccProvider.Meta().(*tailscale.Clients).V1
out, err := client.Webhook(context.Background(), rs.Primary.ID)
client := testAccProvider.Meta().(*tailscale.Clients).V2
out, err := client.Webhooks().Get(context.Background(), rs.Primary.ID)
if err != nil {
return err
}
Expand All @@ -142,7 +142,7 @@ func testAccCheckWebhookExists(resourceName string, webhook *tsclient.Webhook) r
}

func testAccCheckWebhookDestroy(s *terraform.State) error {
client := testAccProvider.Meta().(*tailscale.Clients).V1
client := testAccProvider.Meta().(*tailscale.Clients).V2

for _, rs := range s.RootModule().Resources {
if rs.Type != "tailscale_webhook" {
Expand All @@ -153,7 +153,7 @@ func testAccCheckWebhookDestroy(s *terraform.State) error {
return fmt.Errorf("resource has no ID set")
}

_, err := client.Webhook(context.Background(), rs.Primary.ID)
_, err := client.Webhooks().Get(context.Background(), rs.Primary.ID)
if err == nil {
return fmt.Errorf("webhook %s still exists", rs.Primary.ID)
}
Expand Down

0 comments on commit 886dcc0

Please sign in to comment.