From 8d0556f423bd0d03d899dedc9622e9b16ac9cb21 Mon Sep 17 00:00:00 2001 From: Lee Briggs Date: Mon, 29 Apr 2024 08:53:07 -0700 Subject: [PATCH] Increase allowed 4via6 site ids (#349) * Increase allowed 4via6 site ids fixes #346 * run tfplugindocs --- docs/data-sources/4via6.md | 2 +- tailscale/data_source_4via6.go | 4 ++-- tailscale/data_source_4via6_test.go | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/docs/data-sources/4via6.md b/docs/data-sources/4via6.md index 51a223c7..8bcff278 100644 --- a/docs/data-sources/4via6.md +++ b/docs/data-sources/4via6.md @@ -25,7 +25,7 @@ data "tailscale_4via6" "example" { ### Required - `cidr` (String) The IPv4 CIDR to map -- `site` (Number) Site ID (between 0 and 255) +- `site` (Number) Site ID (between 0 and 65535) ### Read-Only diff --git a/tailscale/data_source_4via6.go b/tailscale/data_source_4via6.go index 277d9622..b917bdf4 100644 --- a/tailscale/data_source_4via6.go +++ b/tailscale/data_source_4via6.go @@ -18,8 +18,8 @@ func dataSource4Via6() *schema.Resource { "site": { Type: schema.TypeInt, Required: true, - Description: "Site ID (between 0 and 255)", - ValidateFunc: validation.IntBetween(0, 255), + Description: "Site ID (between 0 and 65535)", + ValidateFunc: validation.IntBetween(0, 65535), }, "cidr": { Type: schema.TypeString, diff --git a/tailscale/data_source_4via6_test.go b/tailscale/data_source_4via6_test.go index d743dbdd..e6a2e1ac 100644 --- a/tailscale/data_source_4via6_test.go +++ b/tailscale/data_source_4via6_test.go @@ -3,6 +3,7 @@ package tailscale_test import ( "fmt" "net/netip" + "regexp" "strconv" "testing" @@ -18,6 +19,13 @@ data "tailscale_4via6" "example" { } ` +const testDataSource4Via6InvalidSite = ` +data "tailscale_4via6" "invalid" { + site = 70000 + cidr = "10.1.1.0/24" +} +` + func TestProvider_DataSourceTailscale4Via6(t *testing.T) { resource.ParallelTest(t, resource.TestCase{ IsUnitTest: true, @@ -31,6 +39,19 @@ func TestProvider_DataSourceTailscale4Via6(t *testing.T) { }) } +func TestProvider_DataSourceTailscale4Via6_InvalidSite(t *testing.T) { + resource.ParallelTest(t, resource.TestCase{ + IsUnitTest: true, + ProviderFactories: testProviderFactories(t), + Steps: []resource.TestStep{ + { + Config: testDataSource4Via6InvalidSite, + ExpectError: regexp.MustCompile(`expected site to be in the range \(0 - 65535\), got 70000`), + }, + }, + }) +} + func check4Via6Result(n string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -52,6 +73,10 @@ func check4Via6Result(n string) resource.TestCheckFunc { return fmt.Errorf("invalid site ID %q: %s", siteAttr, err) } + if site > 65535 { + return fmt.Errorf("site ID %d is higher than the maximum allowed value of 65535", site) + } + cidrAttr := rs.Primary.Attributes["cidr"] if cidrAttr == "" { return fmt.Errorf("attribute cidr expected to not be nil")