Skip to content

Commit d2be0ba

Browse files
committed
tailscale: use V2 client for acl data source
Updates tailscale/corp#21867 Signed-off-by: Percy Wegmann <[email protected]>
1 parent a7aa735 commit d2be0ba

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

tailscale/data_source_acl_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package tailscale_test
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"testing"
7+
8+
"github.com/google/go-cmp/cmp"
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
11+
12+
"github.com/tailscale/hujson"
13+
"github.com/tailscale/terraform-provider-tailscale/tailscale"
14+
)
15+
16+
func TestAccTailscaleACL(t *testing.T) {
17+
resourceName := "data.tailscale_acl.acl"
18+
19+
resource.Test(t, resource.TestCase{
20+
PreCheck: func() { testAccPreCheck(t) },
21+
ProviderFactories: testAccProviderFactories(t),
22+
Steps: []resource.TestStep{
23+
{
24+
Config: `data "tailscale_acl" "acl" {}`,
25+
Check: func(s *terraform.State) error {
26+
client := testAccProvider.Meta().(*tailscale.Clients).V2
27+
acl, err := client.PolicyFile().Raw(context.Background())
28+
if err != nil {
29+
return fmt.Errorf("unable to get ACL: %s", err)
30+
}
31+
32+
huj, err := hujson.Parse([]byte(acl))
33+
if err != nil {
34+
return fmt.Errorf("Failed to parse ACL as HuJSON: %s", err)
35+
}
36+
expected := huj.String()
37+
38+
rs := s.RootModule().Resources[resourceName].Primary
39+
actual := rs.Attributes["hujson"]
40+
if diff := cmp.Diff(expected, actual); diff != "" {
41+
return fmt.Errorf("wrong ACL (-got, +want): %s", diff)
42+
}
43+
44+
return nil
45+
},
46+
},
47+
},
48+
})
49+
}

0 commit comments

Comments
 (0)