-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tailscale: support policies as HuJSON
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>
- Loading branch information
Showing
9 changed files
with
159 additions
and
127 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
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
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 |
---|---|---|
@@ -1,11 +1,28 @@ | ||
resource "tailscale_acl" "sample_acl" { | ||
resource "tailscale_acl" "as_json" { | ||
acl = jsonencode({ | ||
acls : [ | ||
{ | ||
// Allow all users access to all ports. | ||
action = "accept", | ||
users = ["*"], | ||
ports = ["*:*"], | ||
}], | ||
}, | ||
], | ||
}) | ||
} | ||
|
||
resource "tailscale_acl" "as_hujson" { | ||
acl = <<EOF | ||
{ | ||
// Comments in HuJSON policy are preserved when the policy is applied. | ||
"acls": [ | ||
{ | ||
// Allow all users access to all ports. | ||
action = "accept", | ||
users = ["*"], | ||
ports = ["*:*"], | ||
}, | ||
], | ||
} | ||
EOF | ||
} |
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
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
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
Oops, something went wrong.