-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tailscale: use V2 client for acl data source
Updates tailscale/corp#21867 Signed-off-by: Percy Wegmann <[email protected]>
- Loading branch information
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}, | ||
}, | ||
}, | ||
}) | ||
} |