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

Increase allowed 4via6 site ids #349

Merged
merged 2 commits into from
Apr 29, 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
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
Loading