Skip to content

Commit

Permalink
Increase allowed 4via6 site ids (#349)
Browse files Browse the repository at this point in the history
* Increase allowed 4via6 site ids

fixes #346

* run tfplugindocs
  • Loading branch information
jaxxstorm authored Apr 29, 2024
1 parent 8141642 commit 8d0556f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/data-sources/4via6.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions tailscale/data_source_4via6.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 25 additions & 0 deletions tailscale/data_source_4via6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package tailscale_test
import (
"fmt"
"net/netip"
"regexp"
"strconv"
"testing"

Expand All @@ -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,
Expand All @@ -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]
Expand All @@ -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")
Expand Down

0 comments on commit 8d0556f

Please sign in to comment.