-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added data_tailscale_acl data source (#304)
fixes #180
- Loading branch information
1 parent
95f3d02
commit 43b5098
Showing
3 changed files
with
67 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,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 |
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,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 | ||
} |
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