Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tailscale: support ACL contents as HuJSON #332

Merged
merged 1 commit into from
Feb 15, 2024
Merged

tailscale: support ACL contents as HuJSON #332

merged 1 commit into from
Feb 15, 2024

Conversation

knyar
Copy link
Collaborator

@knyar knyar commented Feb 14, 2024

The acl argument of the tailscale_acl resource can now be a HuJSON string. Instead of unmarshalling acl into an ACL struct of the API client just to have the client serialize it into JSON again, policy content gets passed to the Tailscale API verbatim.

This allows users to define their policy as HuJSON strings, with comments being preserved. Since JSON is a subset of HuJSON, this is backwards compatible, so I am not adding a separate field for this as has been previously suggested in #227.

Validation is now performed by calling the Validate and test policy file API, which will help catch any semantic errors in the policy at terraform plan stage (for example, when a syntactically correct policy contains configuration that is not supported by the Tailnet's current pricing plan).

Finally, this will also allow users to use new fields in the policy without requiring a new release of the Terraform provider.

I've also added a new hujson field to the tailscale_acl data resource that shows current policy as a HuJSON string.

Fixes #331
Fixes #227

The `acl` argument of the `tailscale_acl` resource can now be a HuJSON
string. Instead of unmarshalling `acl` into an `ACL` struct of the [API
client](https://github.com/tailscale/tailscale-client-go) just to have
the client serialize it into JSON again, policy content gets passed
to the Tailscale API verbatim.

This allows users to define their policy as HuJSON strings, with
comments being preserved. Since JSON is a subset of HuJSON, this is
backwards compatible, so I am not adding a separate field for this as
has been previously suggested in #227.

Validation is now performed by calling the [Validate and test policy
file](https://github.com/tailscale/tailscale/blob/main/api.md#validate-and-test-policy-file)
API, which will help catch any semantic errors in the policy at
`terraform plan` stage (for example, when a syntactically correct policy
contains configuration that is not supported by the Tailnet's current
[pricing plan](https://tailscale.com/pricing)).

Finally, this will also allow users to use new fields in the policy
without requiring a new release of the Terraform provider.

I've also added a new `hujson` field to the `tailscale_acl` data
resource that shows current policy as a HuJSON string.

Fixes #331
Fixes #227

Signed-off-by: Anton Tolchanov <anton@tailscale.com>
@knyar knyar changed the title ailscale: support ACL contents as HuJSON tailscale: support ACL contents as HuJSON Feb 14, 2024
@knyar knyar requested review from kradalby and irbekrm February 14, 2024 15:27
Copy link
Member

@kradalby kradalby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat, LGTM

@knyar knyar merged commit 838159a into main Feb 15, 2024
3 checks passed
@knyar knyar deleted the knyar/hujson branch February 15, 2024 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for ACL grants in acl policy Preserve comments in acl file
2 participants