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

added allow_overwrite option to resource_acl #303

Merged
merged 1 commit into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/resources/acl.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ resource "tailscale_acl" "sample_acl" {

- `acl` (String) The JSON-based policy that defines which devices and users are allowed to connect in your network

### Optional

- `overwrite_existing_content` (Boolean) If true, will skip requirement to import acl before allowing changes. Be careful, can cause ACL to be overwritten

### Read-Only

- `id` (String) The ID of this resource.
Expand Down
12 changes: 11 additions & 1 deletion tailscale/resource_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ func resourceACL() *schema.Resource {
ValidateDiagFunc: validateACL,
Description: "The JSON-based policy that defines which devices and users are allowed to connect in your network",
},
"overwrite_existing_content": {
Type: schema.TypeBool,
Optional: true,
Description: "If true, will skip requirement to import acl before allowing changes. Be careful, can cause ACL to be overwritten",
},
},
}
}
Expand Down Expand Up @@ -99,7 +104,12 @@ func resourceACLCreate(ctx context.Context, d *schema.ResourceData, m interface{

// Setting the `ts-default` ETag will make this operation succeed only if
// ACL contents has never been changed from its default value.
if err := client.SetACL(ctx, acl, tailscale.WithETag("ts-default")); err != nil {
var opts []tailscale.SetACLOption
if !d.Get("overwrite_existing_content").(bool) {
opts = append(opts, tailscale.WithETag("ts-default"))
}

if err := client.SetACL(ctx, acl, opts...); err != nil {
if strings.HasSuffix(err.Error(), "(412)") {
err = fmt.Errorf(
"! You seem to be trying to overwrite a non-default ACL with a tailscale_acl resource.\n"+
Expand Down
Loading