Skip to content

Commit

Permalink
added data_tailscale_acl data source (#304)
Browse files Browse the repository at this point in the history
fixes #180
  • Loading branch information
markwellis authored Dec 7, 2023
1 parent 95f3d02 commit 43b5098
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/data-sources/acl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "tailscale_acl Data Source - terraform-provider-tailscale"
subcategory: ""
description: |-
The acl data source gets the Tailscale ACL for a tailnet
---

# tailscale_acl (Data Source)

The acl data source gets the Tailscale ACL for a tailnet



<!-- schema generated by tfplugindocs -->
## Schema

### Read-Only

- `id` (String) The ID of this resource.
- `json` (String) The contents of Tailscale ACL as JSON
45 changes: 45 additions & 0 deletions tailscale/data_source_acl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package tailscale

import (
"context"
"encoding/json"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

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

func dataSourceACL() *schema.Resource {
return &schema.Resource{
Description: "The acl data source gets the Tailscale ACL for a tailnet",
ReadContext: dataSourceACLRead,
Schema: map[string]*schema.Schema{
"json": {
Computed: true,
Type: schema.TypeString,
Description: "The contents of Tailscale ACL as JSON",
},
},
}
}

func dataSourceACLRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
client := m.(*tailscale.Client)

acl, err := client.ACL(ctx)
if err != nil {
return diagnosticsError(err, "Failed to fetch ACL")
}

aclJson, err := json.Marshal(acl)
if err != nil {
return diag.FromErr(err)
}
if err := d.Set("json", string(aclJson)); err != nil {
return diag.Errorf("setting json: %s", err)
}

d.SetId(createUUID())
return nil
}
1 change: 1 addition & 0 deletions tailscale/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func Provider(options ...ProviderOption) *schema.Provider {
"tailscale_device": dataSourceDevice(),
"tailscale_devices": dataSourceDevices(),
"tailscale_4via6": dataSource4Via6(),
"tailscale_acl": dataSourceACL(),
},
}

Expand Down

0 comments on commit 43b5098

Please sign in to comment.