Skip to content

Commit

Permalink
added data_tailscale_acl data source
Browse files Browse the repository at this point in the history
  • Loading branch information
markwellis committed Nov 15, 2023
1 parent 251acf8 commit 3e036c5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
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 acl in a tailnet",
ReadContext: dataSourceAclRead,
Schema: map[string]*schema.Schema{
"json": {
Computed: true,
Type: schema.TypeString,
Description: "the complete acl 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 3e036c5

Please sign in to comment.