Skip to content

Commit

Permalink
tailscale: use V2 client for acl data source
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 23, 2024
1 parent a7aa735 commit d2be0ba
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions tailscale/data_source_acl_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package tailscale_test

import (
"context"
"fmt"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

"github.com/tailscale/hujson"
"github.com/tailscale/terraform-provider-tailscale/tailscale"
)

func TestAccTailscaleACL(t *testing.T) {
resourceName := "data.tailscale_acl.acl"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories(t),
Steps: []resource.TestStep{
{
Config: `data "tailscale_acl" "acl" {}`,
Check: func(s *terraform.State) error {
client := testAccProvider.Meta().(*tailscale.Clients).V2
acl, err := client.PolicyFile().Raw(context.Background())
if err != nil {
return fmt.Errorf("unable to get ACL: %s", err)
}

huj, err := hujson.Parse([]byte(acl))
if err != nil {
return fmt.Errorf("Failed to parse ACL as HuJSON: %s", err)
}
expected := huj.String()

rs := s.RootModule().Resources[resourceName].Primary
actual := rs.Attributes["hujson"]
if diff := cmp.Diff(expected, actual); diff != "" {
return fmt.Errorf("wrong ACL (-got, +want): %s", diff)
}

return nil
},
},
},
})
}

0 comments on commit d2be0ba

Please sign in to comment.