tailscale / terraform-provider-tailscale

Terraform provider for Tailscale
https://registry.terraform.io/providers/tailscale/tailscale
MIT License
255 stars 46 forks source link

added data_tailscale_acl data source #304

Closed markwellis closed 9 months ago

markwellis commented 9 months ago

What this PR does / why we need it: there is currently no acl data_source which makes working with the acl hard

Which issue this PR fixes (use fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged):

Fixes #180

Special notes for your reviewer: I decided to expose it as a json blob as writing a schema and mangling it into that schema at load time was a lot of work and I don't see the benefit. resource "tailscale_acl" takes a json string so it doesn't seem unreasonable that the data source for that would give a json string too Also the external script I've been using up till now also works by providing a json string, which makes this a drop in replacement for that.

It works quite well with this test

data "tailscale_acl" "acl" {}

locals {
  acl = jsondecode(data.tailscale_acl.acl.json)
}

resource "tailscale_acl" "acl" {
  acl = jsonencode(merge(local.acl, {groups = merge(local.acl.groups, {"group:foo" = ["br@asd.com"]})}))

  allow_overwrite = true # in #303 
}

P.s. sorry if the code's not great, it's the first go I've written so I have no idea about best practice etc

markwellis commented 9 months ago

anything you need from me to get this moving?

thanks

knyar commented 9 months ago

anything you need from me to get this moving?

It seems that CI checks are still failing. In this case I think what's missing is running go generate (or tfplugindocs directly) to regenerate markdown docs. Thank you!

markwellis commented 9 months ago

I have updated the PR with tfplugindocs