forked from tailscale/terraform-provider-tailscale
-
Notifications
You must be signed in to change notification settings - Fork 0
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
fixes tailscale#180
- Loading branch information
1 parent
a61467a
commit 8ba5b1c
Showing
2 changed files
with
46 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,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 | ||
} |
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