diff --git a/.github/workflows/acctest.yml b/.github/workflows/acctest.yml index 7328b5e..0fad1c1 100644 --- a/.github/workflows/acctest.yml +++ b/.github/workflows/acctest.yml @@ -25,9 +25,6 @@ jobs: - "v7.3" - "v7" - "latest" - terraform_version: - - "1.2.9" - - "1.3.9" steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 @@ -40,6 +37,6 @@ jobs: - name: TF acceptance tests timeout-minutes: 10 - run: make testacc TF_ACC_TERRAFORM_VERSION=${{ matrix.terraform_version }} + run: make testacc - run: make testacc-down diff --git a/Makefile b/Makefile index bd3f177..3cb1f89 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -export UNIFI_VERSION ?= v7 +export UNIFI_VERSION ?= latest export UNIFI_USERNAME ?= tfacctest export UNIFI_EMAIL ?= tfacctest@example.com export UNIFI_PASSWORD ?= tfacctest1234 diff --git a/go.mod b/go.mod index db61644..284b9ce 100644 --- a/go.mod +++ b/go.mod @@ -18,6 +18,7 @@ require ( github.com/Masterminds/semver/v3 v3.1.1 // indirect github.com/Masterminds/sprig/v3 v3.2.2 // indirect github.com/agext/levenshtein v1.2.3 // indirect + github.com/apparentlymart/go-cidr v1.1.0 // indirect github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect github.com/armon/go-radix v1.0.0 // indirect github.com/bgentry/speakeasy v0.1.0 // indirect diff --git a/go.sum b/go.sum index e635da4..89b179f 100644 --- a/go.sum +++ b/go.sum @@ -19,6 +19,8 @@ github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7l github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= +github.com/apparentlymart/go-cidr v1.1.0 h1:2mAhrMoF+nhXqxTzSZMUzDHkLjmIHC+Zzn4tdgBZjnU= +github.com/apparentlymart/go-cidr v1.1.0/go.mod h1:EBcsNrHc3zQeuaeCeCtQruQm+n9/YjEn/vI25Lg7Gwc= github.com/apparentlymart/go-textseg v1.0.0/go.mod h1:z96Txxhf3xSFMPmb5X/1W05FF/Nj9VFpLOpjS5yuumk= github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec= github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= diff --git a/internal/provider/provider_test.go b/internal/provider/provider_test.go index df551c6..de14967 100644 --- a/internal/provider/provider_test.go +++ b/internal/provider/provider_test.go @@ -3,10 +3,13 @@ package provider import ( "context" "fmt" + "math" + "net" "os" "sync" "testing" + "github.com/apparentlymart/go-cidr/cidr" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" @@ -90,16 +93,26 @@ const ( ) var ( + network = &net.IPNet{ + IP: net.IPv4(10, 0, 0, 0).To4(), + Mask: net.IPv4Mask(255, 0, 0, 0), + } + vlanLock sync.Mutex vlanNext = vlanMin ) -func getTestVLAN(t *testing.T) int { +func getTestVLAN(t *testing.T) (*net.IPNet, int) { vlanLock.Lock() defer vlanLock.Unlock() - vl := vlanNext + vlan := vlanNext vlanNext++ - return vl + subnet, err := cidr.Subnet(network, int(math.Ceil(math.Log2(vlanMax))), vlan) + if err != nil { + t.Error(err) + } + + return subnet, vlan } diff --git a/internal/provider/resource_network_test.go b/internal/provider/resource_network_test.go index 923966c..81d0677 100644 --- a/internal/provider/resource_network_test.go +++ b/internal/provider/resource_network_test.go @@ -2,6 +2,7 @@ package provider import ( "fmt" + "net" "regexp" "strconv" "strings" @@ -13,8 +14,8 @@ import ( func TestAccNetwork_basic(t *testing.T) { name := acctest.RandomWithPrefix("tfacc") - vlanID1 := getTestVLAN(t) - vlanID2 := getTestVLAN(t) + subnet1, vlan1 := getTestVLAN(t) + subnet2, vlan2 := getTestVLAN(t) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { preCheck(t) }, @@ -22,18 +23,18 @@ func TestAccNetwork_basic(t *testing.T) { // TODO: CheckDestroy: , Steps: []resource.TestStep{ { - Config: testAccNetworkConfig(name, vlanID1, true, nil), + Config: testAccNetworkConfig(name, subnet1, vlan1, true, nil), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("unifi_network.test", "domain_name", "foo.local"), - resource.TestCheckResourceAttr("unifi_network.test", "vlan_id", strconv.Itoa(vlanID1)), + resource.TestCheckResourceAttr("unifi_network.test", "vlan_id", strconv.Itoa(vlan1)), resource.TestCheckResourceAttr("unifi_network.test", "igmp_snooping", "true"), ), }, importStep("unifi_network.test"), { - Config: testAccNetworkConfig(name, vlanID2, false, nil), + Config: testAccNetworkConfig(name, subnet2, vlan2, false, nil), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("unifi_network.test", "vlan_id", strconv.Itoa(vlanID2)), + resource.TestCheckResourceAttr("unifi_network.test", "vlan_id", strconv.Itoa(vlan2)), resource.TestCheckResourceAttr("unifi_network.test", "igmp_snooping", "false"), ), }, @@ -51,7 +52,7 @@ func TestAccNetwork_basic(t *testing.T) { func TestAccNetwork_weird_cidr(t *testing.T) { name := acctest.RandomWithPrefix("tfacc") - vlanID := getTestVLAN(t) + subnet, vlan := getTestVLAN(t) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { preCheck(t) }, @@ -59,7 +60,7 @@ func TestAccNetwork_weird_cidr(t *testing.T) { // TODO: CheckDestroy: , Steps: []resource.TestStep{ { - Config: testAccNetworkConfig(name, vlanID, true, nil), + Config: testAccNetworkConfig(name, subnet, vlan, true, nil), Check: resource.ComposeTestCheckFunc( // TODO: ... ), @@ -71,7 +72,7 @@ func TestAccNetwork_weird_cidr(t *testing.T) { func TestAccNetwork_dhcp_dns(t *testing.T) { name := acctest.RandomWithPrefix("tfacc") - vlanID := getTestVLAN(t) + subnet, vlan := getTestVLAN(t) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { preCheck(t) }, @@ -79,14 +80,14 @@ func TestAccNetwork_dhcp_dns(t *testing.T) { // TODO: CheckDestroy: , Steps: []resource.TestStep{ { - Config: testAccNetworkConfig(name, vlanID, true, []string{"192.168.1.101"}), + Config: testAccNetworkConfig(name, subnet, vlan, true, []string{"192.168.1.101"}), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("unifi_network.test", "dhcp_dns.0", "192.168.1.101"), ), }, importStep("unifi_network.test"), { - Config: testAccNetworkConfig(name, vlanID, true, []string{"192.168.1.101", "192.168.1.102"}), + Config: testAccNetworkConfig(name, subnet, vlan, true, []string{"192.168.1.101", "192.168.1.102"}), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("unifi_network.test", "dhcp_dns.0", "192.168.1.101"), resource.TestCheckResourceAttr("unifi_network.test", "dhcp_dns.1", "192.168.1.102"), @@ -94,13 +95,13 @@ func TestAccNetwork_dhcp_dns(t *testing.T) { }, importStep("unifi_network.test"), { - Config: testAccNetworkConfig(name, vlanID, true, nil), + Config: testAccNetworkConfig(name, subnet, vlan, true, nil), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("unifi_network.test", "dhcp_dns.#", "0"), ), }, { - Config: testAccNetworkConfig(name, vlanID, true, []string{"192.168.1.101"}), + Config: testAccNetworkConfig(name, subnet, vlan, true, []string{"192.168.1.101"}), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("unifi_network.test", "dhcp_dns.0", "192.168.1.101"), ), @@ -111,7 +112,7 @@ func TestAccNetwork_dhcp_dns(t *testing.T) { func TestAccNetwork_dhcp_boot(t *testing.T) { name := acctest.RandomWithPrefix("tfacc") - vlanID := getTestVLAN(t) + subnet, vlan := getTestVLAN(t) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { preCheck(t) }, @@ -119,7 +120,7 @@ func TestAccNetwork_dhcp_boot(t *testing.T) { // TODO: CheckDestroy: , Steps: []resource.TestStep{ { - Config: testAccNetworkConfigDHCPBoot(name, vlanID), + Config: testAccNetworkConfigDHCPBoot(name, subnet, vlan), Check: resource.ComposeTestCheckFunc( // TODO: ... ), @@ -131,9 +132,9 @@ func TestAccNetwork_dhcp_boot(t *testing.T) { func TestAccNetwork_v6(t *testing.T) { name := acctest.RandomWithPrefix("tfacc") - vlanID1 := getTestVLAN(t) - vlanID2 := getTestVLAN(t) - vlanID3 := getTestVLAN(t) + subnet1, vlan1 := getTestVLAN(t) + subnet2, vlan2 := getTestVLAN(t) + subnet3, vlan3 := getTestVLAN(t) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { preCheck(t) }, @@ -141,18 +142,18 @@ func TestAccNetwork_v6(t *testing.T) { // TODO: CheckDestroy: , Steps: []resource.TestStep{ { - Config: testAccNetworkConfigV6(name, vlanID1, "static", "fd6a:37be:e362::1/64"), + Config: testAccNetworkConfigV6(name, subnet1, vlan1, "static", "fd6a:37be:e362::1/64"), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("unifi_network.test", "domain_name", "foo.local"), - resource.TestCheckResourceAttr("unifi_network.test", "vlan_id", strconv.Itoa(vlanID1)), + resource.TestCheckResourceAttr("unifi_network.test", "vlan_id", strconv.Itoa(vlan1)), resource.TestCheckResourceAttr("unifi_network.test", "ipv6_static_subnet", "fd6a:37be:e362::1/64"), ), }, importStep("unifi_network.test"), { - Config: testAccNetworkConfigV6(name, vlanID2, "static", "fd6a:37be:e363::1/64"), + Config: testAccNetworkConfigV6(name, subnet2, vlan2, "static", "fd6a:37be:e363::1/64"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("unifi_network.test", "vlan_id", strconv.Itoa(vlanID2)), + resource.TestCheckResourceAttr("unifi_network.test", "vlan_id", strconv.Itoa(vlan2)), resource.TestCheckResourceAttr("unifi_network.test", "ipv6_static_subnet", "fd6a:37be:e363::1/64"), ), }, @@ -160,13 +161,14 @@ func TestAccNetwork_v6(t *testing.T) { { Config: testAccNetworkConfigDhcpV6( name, - vlanID3, + subnet3, + vlan3, "fd6a:37be:e364::1/64", "fd6a:37be:e364::2", "fd6a:37be:e364::7d1", []string{"2001:4860:4860::8888", "2001:4860:4860::8844"}), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("unifi_network.test", "vlan_id", strconv.Itoa(vlanID3)), + resource.TestCheckResourceAttr("unifi_network.test", "vlan_id", strconv.Itoa(vlan3)), resource.TestCheckResourceAttr("unifi_network.test", "dhcp_v6_start", "fd6a:37be:e364::2"), resource.TestCheckResourceAttr("unifi_network.test", "dhcp_v6_stop", "fd6a:37be:e364::7d1"), resource.TestCheckResourceAttr("unifi_network.test", "dhcp_v6_lease", strconv.Itoa(12*60*60)), @@ -175,7 +177,8 @@ func TestAccNetwork_v6(t *testing.T) { { Config: testAccNetworkConfigDhcpV6( name, - vlanID3, + subnet3, + vlan3, "fd6a:37be:e365::1/64", "fd6a:37be:e364::2", "fd6a:37be:e364::7d1", @@ -261,8 +264,8 @@ func TestAccNetwork_wan(t *testing.T) { func TestAccNetwork_differentSite(t *testing.T) { name := acctest.RandomWithPrefix("tfacc") - vlanID1 := getTestVLAN(t) - vlanID2 := getTestVLAN(t) + subnet1, vlan1 := getTestVLAN(t) + subnet2, vlan2 := getTestVLAN(t) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { preCheck(t) }, @@ -270,7 +273,7 @@ func TestAccNetwork_differentSite(t *testing.T) { // TODO: CheckDestroy: , Steps: []resource.TestStep{ { - Config: testAccNetworkWithSiteConfig(name, vlanID1), + Config: testAccNetworkWithSiteConfig(name, subnet1, vlan1), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrPair("unifi_network.test", "site", "unifi_site.test", "name"), ), @@ -282,7 +285,7 @@ func TestAccNetwork_differentSite(t *testing.T) { ImportStateVerify: true, }, { - Config: testAccNetworkWithSiteConfig(name, vlanID2), + Config: testAccNetworkWithSiteConfig(name, subnet2, vlan2), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrPair("unifi_network.test", "site", "unifi_site.test", "name"), ), @@ -299,9 +302,9 @@ func TestAccNetwork_differentSite(t *testing.T) { func TestAccNetwork_importByName(t *testing.T) { name := acctest.RandomWithPrefix("tfacc") - vlanID1 := getTestVLAN(t) - vlanID2 := getTestVLAN(t) - vlanID3 := getTestVLAN(t) + subnet1, vlan1 := getTestVLAN(t) + subnet2, vlan2 := getTestVLAN(t) + subnet3, vlan3 := getTestVLAN(t) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { preCheck(t) }, @@ -309,10 +312,10 @@ func TestAccNetwork_importByName(t *testing.T) { Steps: []resource.TestStep{ // Apply and import network by name. { - Config: testAccNetworkConfig(name, vlanID1, true, nil), + Config: testAccNetworkConfig(name, subnet1, vlan1, true, nil), }, { - Config: testAccNetworkConfig(name, vlanID1, true, nil), + Config: testAccNetworkConfig(name, subnet1, vlan1, true, nil), ResourceName: "unifi_network.test", ImportState: true, ImportStateVerify: true, @@ -320,11 +323,11 @@ func TestAccNetwork_importByName(t *testing.T) { }, // Apply and test errors. { - Config: testAccNetworkWithDuplicateNames(vlanID2, vlanID3, "DUPLICATE_NAME"), + Config: testAccNetworkWithDuplicateNames(subnet2, vlan2, subnet3, vlan3, "DUPLICATE_NAME"), }, // Test error on name that doesn't exist. { - Config: testAccNetworkWithDuplicateNames(vlanID2, vlanID3, "DUPLICATE_NAME"), + Config: testAccNetworkWithDuplicateNames(subnet2, vlan2, subnet3, vlan3, "DUPLICATE_NAME"), ResourceName: "unifi_network.test1", ImportState: true, ImportStateVerify: true, @@ -333,7 +336,7 @@ func TestAccNetwork_importByName(t *testing.T) { }, // Test error on multiple matches. { - Config: testAccNetworkWithDuplicateNames(vlanID2, vlanID3, "DUPLICATE_NAME"), + Config: testAccNetworkWithDuplicateNames(subnet2, vlan2, subnet3, vlan3, "DUPLICATE_NAME"), ResourceName: "unifi_network.test1", ImportState: true, ImportStateVerify: true, @@ -346,7 +349,7 @@ func TestAccNetwork_importByName(t *testing.T) { func TestAccNetwork_dhcpRelay(t *testing.T) { name := acctest.RandomWithPrefix("tfacc") - vlanID := getTestVLAN(t) + subnet, vlan := getTestVLAN(t) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { @@ -356,14 +359,14 @@ func TestAccNetwork_dhcpRelay(t *testing.T) { // TODO: CheckDestroy: , Steps: []resource.TestStep{ { - Config: testAccNetworkConfigDHCPRelay(name, vlanID, true), + Config: testAccNetworkConfigDHCPRelay(name, subnet, vlan, true), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("unifi_network.test", "dhcp_relay_enabled", "true"), ), }, importStep("unifi_network.test"), { - Config: testAccNetworkConfigDHCPRelay(name, vlanID, false), + Config: testAccNetworkConfigDHCPRelay(name, subnet, vlan, false), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("unifi_network.test", "dhcp_relay_enabled", "false"), ), @@ -375,7 +378,7 @@ func TestAccNetwork_dhcpRelay(t *testing.T) { func TestAccNetwork_vlanOnly(t *testing.T) { name := acctest.RandomWithPrefix("tfacc") - vlanID := getTestVLAN(t) + _, vlan := getTestVLAN(t) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { @@ -385,9 +388,9 @@ func TestAccNetwork_vlanOnly(t *testing.T) { // TODO: CheckDestroy: , Steps: []resource.TestStep{ { - Config: testAccNetworkVlanOnly(name, vlanID), + Config: testAccNetworkVlanOnly(name, vlan), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("unifi_network.test", "vlan_id", strconv.Itoa(vlanID)), + resource.TestCheckResourceAttr("unifi_network.test", "vlan_id", strconv.Itoa(vlan)), ), }, { @@ -410,11 +413,11 @@ func quoteStrings(src []string) []string { return dst } -func testAccNetworkConfigDHCPBoot(name string, vlan int) string { +func testAccNetworkConfigDHCPBoot(name string, subnet *net.IPNet, vlan int) string { return fmt.Sprintf(` locals { - subnet = cidrsubnet("10.0.0.0/8", 6, %[2]d) - vlan_id = %[2]d + subnet = "%[2]s" + vlan_id = %[3]d } resource "unifi_network" "test" { @@ -434,14 +437,14 @@ resource "unifi_network" "test" { dhcp_dns = ["192.168.1.101", "192.168.1.102"] } -`, name, vlan) +`, name, subnet, vlan) } -func testAccNetworkConfig(name string, vlan int, igmpSnoop bool, dhcpDNS []string) string { +func testAccNetworkConfig(name string, subnet *net.IPNet, vlan int, igmpSnoop bool, dhcpDNS []string) string { return fmt.Sprintf(` locals { - subnet = cidrsubnet("10.0.0.0/8", 6, %[2]d) - vlan_id = %[2]d + subnet = "%[2]s" + vlan_id = %[3]d } resource "unifi_network" "test" { @@ -454,18 +457,18 @@ resource "unifi_network" "test" { dhcp_stop = cidrhost(local.subnet, 254) dhcp_enabled = true domain_name = "foo.local" - igmp_snooping = %[3]t + igmp_snooping = %[4]t - dhcp_dns = [%[4]s] + dhcp_dns = [%[5]s] } -`, name, vlan, igmpSnoop, strings.Join(quoteStrings(dhcpDNS), ",")) +`, name, subnet, vlan, igmpSnoop, strings.Join(quoteStrings(dhcpDNS), ",")) } -func testAccNetworkConfigV6(name string, vlan int, ipv6Type string, ipv6Subnet string) string { +func testAccNetworkConfigV6(name string, subnet *net.IPNet, vlan int, ipv6Type string, ipv6Subnet string) string { return fmt.Sprintf(` locals { - subnet = cidrsubnet("10.0.0.0/8", 6, %[2]d) - vlan_id = %[2]d + subnet = "%[2]s" + vlan_id = %[3]d } resource "unifi_network" "test" { @@ -479,11 +482,11 @@ resource "unifi_network" "test" { dhcp_enabled = true domain_name = "foo.local" - ipv6_interface_type = "%[3]s" - ipv6_static_subnet = "%[4]s" + ipv6_interface_type = "%[4]s" + ipv6_static_subnet = "%[5]s" ipv6_ra_enable = true } -`, name, vlan, ipv6Type, ipv6Subnet) +`, name, subnet, vlan, ipv6Type, ipv6Subnet) } func testWanNetworkConfig(name string, networkGroup string, wanType string, wanIP string, wanEgressQOS int, wanUsername string, wanPassword string, wanDNS1 string, wanDNS2 string) string { @@ -531,11 +534,11 @@ resource "unifi_network" "wan_test" { `, name, wanTypeV6, wanDhcpV6PdSize) } -func testAccNetworkWithSiteConfig(name string, vlan int) string { +func testAccNetworkWithSiteConfig(name string, subnet *net.IPNet, vlan int) string { return fmt.Sprintf(` locals { - subnet = cidrsubnet("10.0.0.0/8", 6, %[2]d) - vlan_id = %[2]d + subnet = "%[2]s" + vlan_id = %[3]d } resource "unifi_site" "test" { @@ -555,20 +558,20 @@ resource "unifi_network" "test" { domain_name = "foo.local" igmp_snooping = true } -`, name, vlan) +`, name, subnet, vlan) } -func testAccNetworkWithDuplicateNames(vlan1, vlan2 int, networkName string) string { +func testAccNetworkWithDuplicateNames(subnet1 *net.IPNet, vlan1 int, subnet2 *net.IPNet, vlan2 int, networkName string) string { return fmt.Sprintf(` locals { - subnet1 = cidrsubnet("10.0.0.0/8", 6, %[1]d) - vlan_id1 = %[1]d - subnet2 = cidrsubnet("10.0.0.0/8", 6, %[2]d) - vlan_id2 = %[2]d + subnet1 = "%[1]s" + vlan_id1 = %[2]d + subnet2 = "%[3]s" + vlan_id2 = %[4]d } resource "unifi_network" "test1" { - name = "%[3]s" + name = "%[5]s" purpose = "corporate" subnet = local.subnet1 @@ -576,20 +579,20 @@ resource "unifi_network" "test1" { } resource "unifi_network" "test2" { - name = "%[3]s" + name = "%[5]s" purpose = "corporate" subnet = local.subnet2 vlan_id = local.vlan_id2 } -`, vlan1, vlan2, networkName) +`, subnet1, vlan1, subnet2, vlan2, networkName) } -func testAccNetworkConfigDHCPRelay(name string, vlan int, dhcpRelay bool) string { +func testAccNetworkConfigDHCPRelay(name string, subnet *net.IPNet, vlan int, dhcpRelay bool) string { return fmt.Sprintf(` locals { - subnet = cidrsubnet("10.0.0.0/8", 6, %[2]d) - vlan_id = %[2]d + subnet = "%[2]s" + vlan_id = %[3]d } resource "unifi_network" "test" { @@ -600,9 +603,9 @@ resource "unifi_network" "test" { vlan_id = local.vlan_id domain_name = "foo.local" - dhcp_relay_enabled = %[3]t + dhcp_relay_enabled = %[4]t } -`, name, vlan, dhcpRelay) +`, name, subnet, vlan, dhcpRelay) } func testAccNetworkVlanOnly(name string, vlan int) string { @@ -620,11 +623,11 @@ resource "unifi_network" "test" { `, name, vlan) } -func testAccNetworkConfigDhcpV6(name string, vlan int, gatewayIP string, dhcpdV6Start string, dhcpdV6Stop string, dhcpV6DNS []string) string { +func testAccNetworkConfigDhcpV6(name string, subnet *net.IPNet, vlan int, gatewayIP string, dhcpdV6Start string, dhcpdV6Stop string, dhcpV6DNS []string) string { return fmt.Sprintf(` locals { - subnet = cidrsubnet("10.0.0.0/8", 6, %[2]d) - vlan_id = %[2]d + subnet = "%[2]s" + vlan_id = %[3]d } resource "unifi_network" "test" { @@ -634,14 +637,14 @@ resource "unifi_network" "test" { subnet = local.subnet vlan_id = local.vlan_id - ipv6_static_subnet = "%[3]s" + ipv6_static_subnet = "%[4]s" dhcp_v6_dns_auto = false - dhcp_v6_dns = [%[6]s] + dhcp_v6_dns = [%[7]s] dhcp_v6_enabled = true - dhcp_v6_start = "%[4]s" - dhcp_v6_stop = "%[5]s" + dhcp_v6_start = "%[5]s" + dhcp_v6_stop = "%[6]s" dhcp_v6_lease = 12 * 60 * 60 } -`, name, vlan, gatewayIP, dhcpdV6Start, dhcpdV6Stop, strings.Join(quoteStrings(dhcpV6DNS), ",")) +`, name, subnet, vlan, gatewayIP, dhcpdV6Start, dhcpdV6Stop, strings.Join(quoteStrings(dhcpV6DNS), ",")) } diff --git a/internal/provider/resource_user_test.go b/internal/provider/resource_user_test.go index 701f109..8c7a4db 100644 --- a/internal/provider/resource_user_test.go +++ b/internal/provider/resource_user_test.go @@ -9,6 +9,7 @@ import ( "strings" "testing" + "github.com/apparentlymart/go-cidr/cidr" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "github.com/paultyng/go-unifi/unifi" @@ -60,7 +61,12 @@ func TestAccUser_basic(t *testing.T) { func TestAccUser_fixed_ip(t *testing.T) { mac := generateTestMac() - vlanID := 301 + subnet, vlan := getTestVLAN(t) + + ip, err := cidr.Host(subnet, 1) + if err != nil { + t.Error(err) + } resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { preCheck(t) }, @@ -76,10 +82,10 @@ func TestAccUser_fixed_ip(t *testing.T) { }, userImportStep("unifi_user.test"), { - Config: testAccUserConfig_fixedIP(vlanID, mac), + Config: testAccUserConfig_fixedIP(subnet, vlan, mac, &ip), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), - resource.TestCheckResourceAttr("unifi_user.test", "fixed_ip", "10.1.10.50"), + resource.TestCheckResourceAttr("unifi_user.test", "fixed_ip", ip.String()), ), }, userImportStep("unifi_user.test"), @@ -87,7 +93,7 @@ func TestAccUser_fixed_ip(t *testing.T) { // this passes the network again even though its not used // to avoid a destroy order of operations issue, can // maybe work it out some other way - Config: testAccUserConfig_network(vlanID) + testAccUserConfig(mac, "tfacc", "tfacc fixed ip"), + Config: testAccUserConfig_network(subnet, vlan) + testAccUserConfig(mac, "tfacc", "tfacc fixed ip"), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), resource.TestCheckResourceAttr("unifi_user.test", "fixed_ip", ""), @@ -234,7 +240,12 @@ func TestAccUser_fingerprint(t *testing.T) { func TestAccUser_localdns(t *testing.T) { testMAC := generateTestMac() - vlanID := 301 + subnet, vlan := getTestVLAN(t) + + ip, err := cidr.Host(subnet, 1) + if err != nil { + t.Error(err) + } resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { @@ -252,14 +263,14 @@ func TestAccUser_localdns(t *testing.T) { }, userImportStep("unifi_user.test"), { - Config: testAccUserConfig_localdns(vlanID, testMAC, "tfacc", "resource.example.com"), + Config: testAccUserConfig_localdns(subnet, vlan, testMAC, "tfacc", "resource.example.com", &ip), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("unifi_user.test", "local_dns_record", "resource.example.com"), ), }, userImportStep("unifi_user.test"), { - Config: testAccUserConfig_localdns(vlanID, testMAC, "tfacc", ""), + Config: testAccUserConfig_localdns(subnet, vlan, testMAC, "tfacc", "", &ip), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttr("unifi_user.test", "local_dns_record", ""), ), @@ -300,36 +311,32 @@ resource "unifi_user" "test" { `, mac, name, note) } -func testAccUserConfig_network(vlanID int) string { +func testAccUserConfig_network(subnet *net.IPNet, vlan int) string { return fmt.Sprintf(` -variable "subnet" { - default = "10.1.10.1/24" -} - resource "unifi_network" "test" { name = "tfaccfixedip" purpose = "corporate" - vlan_id = %d - subnet = var.subnet - dhcp_start = cidrhost(var.subnet, 6) - dhcp_stop = cidrhost(var.subnet, 254) + vlan_id = %[2]d + subnet = "%[1]s" + dhcp_start = cidrhost("%[1]s", 6) + dhcp_stop = cidrhost("%[1]s", 254) dhcp_enabled = true } -`, vlanID) +`, subnet, vlan) } -func testAccUserConfig_fixedIP(vlanID int, mac string) string { - return fmt.Sprintf(testAccUserConfig_network(vlanID)+` +func testAccUserConfig_fixedIP(subnet *net.IPNet, vlan int, mac string, ip *net.IP) string { + return fmt.Sprintf(testAccUserConfig_network(subnet, vlan)+` resource "unifi_user" "test" { - mac = "%s" + mac = "%[1]s" name = "tfacc" note = "tfacc fixed ip" - fixed_ip = "10.1.10.50" + fixed_ip = "%[2]s" network_id = unifi_network.test.id } -`, mac) +`, mac, ip) } func testAccUserConfig_block(mac string, blocked bool) string { @@ -367,15 +374,15 @@ resource "unifi_user" "test" { `, mac, name, devIdOverride) } -func testAccUserConfig_localdns(vlanID int, mac, name string, localDnsRecord string) string { - return fmt.Sprintf(testAccUserConfig_network(vlanID)+` +func testAccUserConfig_localdns(subnet *net.IPNet, vlan int, mac, name string, localDnsRecord string, ip *net.IP) string { + return fmt.Sprintf(testAccUserConfig_network(subnet, vlan)+` resource "unifi_user" "test" { - mac = "%s" - name = "%s" + mac = "%[1]s" + name = "%[2]s" - fixed_ip = "10.1.10.50" + fixed_ip = "%[4]s" network_id = unifi_network.test.id - local_dns_record = "%s" + local_dns_record = "%[3]s" } -`, mac, name, localDnsRecord) +`, mac, name, localDnsRecord, ip) } diff --git a/internal/provider/resource_wlan_test.go b/internal/provider/resource_wlan_test.go index 7544ac3..8e59495 100644 --- a/internal/provider/resource_wlan_test.go +++ b/internal/provider/resource_wlan_test.go @@ -2,6 +2,7 @@ package provider import ( "fmt" + "net" "os" "strconv" "testing" @@ -38,7 +39,7 @@ func wlanPreCheck(t *testing.T) { } func TestAccWLAN_wpapsk(t *testing.T) { - vlanID := getTestVLAN(t) + subnet, vlan := getTestVLAN(t) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { preCheck(t) @@ -53,7 +54,7 @@ func TestAccWLAN_wpapsk(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: testAccWLANConfig_wpapsk(vlanID, "disabled"), + Config: testAccWLANConfig_wpapsk(subnet, vlan, "disabled"), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), @@ -64,7 +65,7 @@ func TestAccWLAN_wpapsk(t *testing.T) { } func TestAccWLAN_open(t *testing.T) { - vlanID := getTestVLAN(t) + subnet, vlan := getTestVLAN(t) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { preCheck(t) @@ -79,21 +80,21 @@ func TestAccWLAN_open(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: testAccWLANConfig_open(vlanID), + Config: testAccWLANConfig_open(subnet, vlan), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), }, importStep("unifi_wlan.test"), { - Config: testAccWLANConfig_open_mac_filter(vlanID), + Config: testAccWLANConfig_open_mac_filter(subnet, vlan), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), }, importStep("unifi_wlan.test"), { - Config: testAccWLANConfig_open(vlanID), + Config: testAccWLANConfig_open(subnet, vlan), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), @@ -104,7 +105,7 @@ func TestAccWLAN_open(t *testing.T) { } func TestAccWLAN_change_security_and_pmf(t *testing.T) { - vlanID := getTestVLAN(t) + subnet, vlan := getTestVLAN(t) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { preCheck(t) @@ -119,35 +120,35 @@ func TestAccWLAN_change_security_and_pmf(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: testAccWLANConfig_wpapsk(vlanID, "disabled"), + Config: testAccWLANConfig_wpapsk(subnet, vlan, "disabled"), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), }, importStep("unifi_wlan.test"), { - Config: testAccWLANConfig_open(vlanID), + Config: testAccWLANConfig_open(subnet, vlan), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), }, importStep("unifi_wlan.test"), { - Config: testAccWLANConfig_wpapsk(vlanID, "optional"), + Config: testAccWLANConfig_wpapsk(subnet, vlan, "optional"), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), }, importStep("unifi_wlan.test"), { - Config: testAccWLANConfig_wpapsk(vlanID, "required"), + Config: testAccWLANConfig_wpapsk(subnet, vlan, "required"), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), }, importStep("unifi_wlan.test"), { - Config: testAccWLANConfig_wpapsk(vlanID, "disabled"), + Config: testAccWLANConfig_wpapsk(subnet, vlan, "disabled"), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), @@ -158,7 +159,7 @@ func TestAccWLAN_change_security_and_pmf(t *testing.T) { } func TestAccWLAN_schedule(t *testing.T) { - vlanID := getTestVLAN(t) + subnet, vlan := getTestVLAN(t) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { preCheck(t) @@ -173,7 +174,7 @@ func TestAccWLAN_schedule(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: testAccWLANConfig_schedule(vlanID), + Config: testAccWLANConfig_schedule(subnet, vlan), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), @@ -181,7 +182,7 @@ func TestAccWLAN_schedule(t *testing.T) { importStep("unifi_wlan.test"), // remove schedule { - Config: testAccWLANConfig_open(vlanID), + Config: testAccWLANConfig_open(subnet, vlan), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), @@ -192,7 +193,7 @@ func TestAccWLAN_schedule(t *testing.T) { } func TestAccWLAN_wpaeap(t *testing.T) { - vlanID := getTestVLAN(t) + subnet, vlan := getTestVLAN(t) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { @@ -208,7 +209,7 @@ func TestAccWLAN_wpaeap(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: testAccWLANConfig_wpaeap(vlanID), + Config: testAccWLANConfig_wpaeap(subnet, vlan), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), @@ -219,7 +220,7 @@ func TestAccWLAN_wpaeap(t *testing.T) { } func TestAccWLAN_wlan_band(t *testing.T) { - vlanID := getTestVLAN(t) + subnet, vlan := getTestVLAN(t) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { preCheck(t) @@ -234,7 +235,7 @@ func TestAccWLAN_wlan_band(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: testAccWLANConfig_wlan_band(vlanID), + Config: testAccWLANConfig_wlan_band(subnet, vlan), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), @@ -245,7 +246,7 @@ func TestAccWLAN_wlan_band(t *testing.T) { } func TestAccWLAN_no2ghz_oui(t *testing.T) { - vlanID := getTestVLAN(t) + subnet, vlan := getTestVLAN(t) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { preCheck(t) @@ -260,7 +261,7 @@ func TestAccWLAN_no2ghz_oui(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: testAccWLANConfig_no2ghz_oui(vlanID), + Config: testAccWLANConfig_no2ghz_oui(subnet, vlan), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), @@ -271,7 +272,7 @@ func TestAccWLAN_no2ghz_oui(t *testing.T) { } func TestAccWLAN_uapsd(t *testing.T) { - vlanID := getTestVLAN(t) + subnet, vlan := getTestVLAN(t) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { preCheck(t) @@ -286,7 +287,7 @@ func TestAccWLAN_uapsd(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: testAccWLANConfig_uapsd(vlanID), + Config: testAccWLANConfig_uapsd(subnet, vlan), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), @@ -297,7 +298,7 @@ func TestAccWLAN_uapsd(t *testing.T) { } func TestAccWLAN_wpa3(t *testing.T) { - vlanID := getTestVLAN(t) + subnet, vlan := getTestVLAN(t) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { preCheck(t) @@ -313,21 +314,21 @@ func TestAccWLAN_wpa3(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: testAccWLANConfig_wpa3(vlanID, false, "required"), + Config: testAccWLANConfig_wpa3(subnet, vlan, false, "required"), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), }, importStep("unifi_wlan.test"), { - Config: testAccWLANConfig_wpa3(vlanID, true, "optional"), + Config: testAccWLANConfig_wpa3(subnet, vlan, true, "optional"), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), }, importStep("unifi_wlan.test"), { - Config: testAccWLANConfig_wpa3(vlanID, false, "required"), + Config: testAccWLANConfig_wpa3(subnet, vlan, false, "required"), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), @@ -338,7 +339,7 @@ func TestAccWLAN_wpa3(t *testing.T) { } func TestAccWLAN_minimum_data_rate(t *testing.T) { - vlanID := getTestVLAN(t) + subnet, vlan := getTestVLAN(t) resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { preCheck(t) @@ -353,35 +354,35 @@ func TestAccWLAN_minimum_data_rate(t *testing.T) { }, Steps: []resource.TestStep{ { - Config: testAccWLANConfig_minimum_data_rate(vlanID, 5500, 18000), + Config: testAccWLANConfig_minimum_data_rate(subnet, vlan, 5500, 18000), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), }, importStep("unifi_wlan.test"), { - Config: testAccWLANConfig_minimum_data_rate(vlanID, 1000, 18000), + Config: testAccWLANConfig_minimum_data_rate(subnet, vlan, 1000, 18000), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), }, importStep("unifi_wlan.test"), { - Config: testAccWLANConfig_minimum_data_rate(vlanID, 0, 0), + Config: testAccWLANConfig_minimum_data_rate(subnet, vlan, 0, 0), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), }, importStep("unifi_wlan.test"), { - Config: testAccWLANConfig_minimum_data_rate(vlanID, 6000, 9000), + Config: testAccWLANConfig_minimum_data_rate(subnet, vlan, 6000, 9000), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), }, importStep("unifi_wlan.test"), { - Config: testAccWLANConfig_minimum_data_rate(vlanID, 18000, 6000), + Config: testAccWLANConfig_minimum_data_rate(subnet, vlan, 18000, 6000), Check: resource.ComposeTestCheckFunc( // testCheckNetworkExists(t, "name"), ), @@ -391,88 +392,78 @@ func TestAccWLAN_minimum_data_rate(t *testing.T) { }) } -func testAccWLANConfig_wpapsk(vlanID int, pmf string) string { +func testAccWLANConfig_wpapsk(subnet *net.IPNet, vlan int, pmf string) string { return fmt.Sprintf(` -data "unifi_ap_group" "default" { -} +data "unifi_ap_group" "default" {} -data "unifi_user_group" "default" { -} +data "unifi_user_group" "default" {} resource "unifi_network" "test" { name = "tfacc" purpose = "corporate" - - subnet = cidrsubnet("10.0.0.0/8", 6, %[1]d) - vlan_id = %[1]d + subnet = "%[1]s" + vlan_id = %[2]d } resource "unifi_wlan" "test" { name = "tfacc-wpapsk" network_id = unifi_network.test.id passphrase = "12345678" - ap_group_ids = [data.unifi_ap_group.default.id] + ap_group_ids = [data.unifi_ap_group.default.id] user_group_id = data.unifi_user_group.default.id security = "wpapsk" multicast_enhance = true - pmf_mode = %[2]q + pmf_mode = %[3]q } -`, vlanID, pmf) +`, subnet, vlan, pmf) } -func testAccWLANConfig_wpaeap(vlanID int) string { +func testAccWLANConfig_wpaeap(subnet *net.IPNet, vlan int) string { return fmt.Sprintf(` -data "unifi_ap_group" "default" { -} +data "unifi_ap_group" "default" {} -data "unifi_user_group" "default" { -} +data "unifi_user_group" "default" {} -data "unifi_radius_profile" "default" { -} +data "unifi_radius_profile" "default" {} resource "unifi_setting_radius" "this" { enabled = true - secret = "securepw" + secret = "securepw" } resource "unifi_network" "test" { name = "tfacc" purpose = "corporate" - - subnet = cidrsubnet("10.0.0.0/8", 6, %[1]d) - vlan_id = %[1]d + subnet = "%[1]s" + vlan_id = %[2]d } resource "unifi_wlan" "test" { name = "tfacc-wpapsk" network_id = unifi_network.test.id passphrase = "12345678" - ap_group_ids = [data.unifi_ap_group.default.id] + ap_group_ids = [data.unifi_ap_group.default.id] user_group_id = data.unifi_user_group.default.id security = "wpaeap" radius_profile_id = data.unifi_radius_profile.default.id } -`, vlanID) +`, subnet, vlan) } -func testAccWLANConfig_open(vlanID int) string { +func testAccWLANConfig_open(subnet *net.IPNet, vlan int) string { return fmt.Sprintf(` -data "unifi_ap_group" "default" { -} +data "unifi_ap_group" "default" {} -data "unifi_user_group" "default" { -} +data "unifi_user_group" "default" {} resource "unifi_network" "test" { name = "tfacc" purpose = "corporate" - - subnet = cidrsubnet("10.0.0.0/8", 6, %[1]d) - vlan_id = %[1]d + subnet = "%[1]s" + vlan_id = %[2]d } resource "unifi_wlan" "test" { @@ -482,75 +473,69 @@ resource "unifi_wlan" "test" { user_group_id = data.unifi_user_group.default.id security = "open" } -`, vlanID) +`, subnet, vlan) } -func testAccWLANConfig_schedule(vlanID int) string { +func testAccWLANConfig_schedule(subnet *net.IPNet, vlan int) string { return fmt.Sprintf(` -data "unifi_ap_group" "default" { -} +data "unifi_ap_group" "default" {} -data "unifi_user_group" "default" { -} +data "unifi_user_group" "default" {} resource "unifi_network" "test" { name = "tfacc" purpose = "corporate" - - subnet = cidrsubnet("10.0.0.0/8", 6, %[1]d) - vlan_id = %[1]d + subnet = "%[1]s" + vlan_id = %[2]d } resource "unifi_wlan" "test" { name = "tfacc-open-schedule" network_id = unifi_network.test.id - ap_group_ids = [data.unifi_ap_group.default.id] + ap_group_ids = [data.unifi_ap_group.default.id] user_group_id = data.unifi_user_group.default.id security = "open" schedule { day_of_week = "mon" - start_hour = 3 - duration = 60*6 + start_hour = 3 + duration = 60*6 } schedule { - day_of_week = "wed" - start_hour = 13 + day_of_week = "wed" + start_hour = 13 start_minute = 30 - duration = (60*3)+30 - name = "minute" + duration = (60*3)+30 + name = "minute" } schedule { day_of_week = "thu" - start_hour = 19 - duration = 60*1 + start_hour = 19 + duration = 60*1 } schedule { day_of_week = "fri" - start_hour = 19 - duration = 60*1 + start_hour = 19 + duration = 60*1 } } -`, vlanID) +`, subnet, vlan) } -func testAccWLANConfig_open_mac_filter(vlanID int) string { +func testAccWLANConfig_open_mac_filter(subnet *net.IPNet, vlan int) string { return fmt.Sprintf(` -data "unifi_ap_group" "default" { -} +data "unifi_ap_group" "default" {} -data "unifi_user_group" "default" { -} +data "unifi_user_group" "default" {} resource "unifi_network" "test" { name = "tfacc" purpose = "corporate" - - subnet = cidrsubnet("10.0.0.0/8", 6, %[1]d) - vlan_id = %[1]d + subnet = "%[1]s" + vlan_id = %[2]d } resource "unifi_wlan" "test" { @@ -564,83 +549,72 @@ resource "unifi_wlan" "test" { mac_filter_list = ["ab:cd:ef:12:34:56"] mac_filter_policy = "allow" } -`, vlanID) +`, subnet, vlan) } -func testAccWLANConfig_wlan_band(vlanID int) string { +func testAccWLANConfig_wlan_band(subnet *net.IPNet, vlan int) string { return fmt.Sprintf(` -data "unifi_ap_group" "default" { -} +data "unifi_ap_group" "default" {} -data "unifi_user_group" "default" { -} +data "unifi_user_group" "default" {} resource "unifi_network" "test" { name = "tfacc" purpose = "corporate" - - subnet = cidrsubnet("10.0.0.0/8", 6, %[1]d) - vlan_id = %[1]d + subnet = "%[1]s" + vlan_id = %[2]d } resource "unifi_wlan" "test" { - name = "tfacc-wpapsk" - network_id = unifi_network.test.id - passphrase = "12345678" - ap_group_ids = [data.unifi_ap_group.default.id] - user_group_id = data.unifi_user_group.default.id - security = "wpapsk" - wlan_band = "5g" - + name = "tfacc-wpapsk" + network_id = unifi_network.test.id + passphrase = "12345678" + ap_group_ids = [data.unifi_ap_group.default.id] + user_group_id = data.unifi_user_group.default.id + security = "wpapsk" + wlan_band = "5g" multicast_enhance = true } -`, vlanID) +`, subnet, vlan) } -func testAccWLANConfig_no2ghz_oui(vlanID int) string { +func testAccWLANConfig_no2ghz_oui(subnet *net.IPNet, vlan int) string { return fmt.Sprintf(` -data "unifi_ap_group" "default" { -} +data "unifi_ap_group" "default" {} -data "unifi_user_group" "default" { -} +data "unifi_user_group" "default" {} resource "unifi_network" "test" { name = "tfacc" purpose = "corporate" - - subnet = cidrsubnet("10.0.0.0/8", 6, %[1]d) - vlan_id = %[1]d + subnet = "%[1]s" + vlan_id = %[2]d } resource "unifi_wlan" "test" { - name = "tfacc-wpapsk" - network_id = unifi_network.test.id - passphrase = "12345678" - ap_group_ids = [data.unifi_ap_group.default.id] - user_group_id = data.unifi_user_group.default.id - security = "wpapsk" - no2ghz_oui = false - + name = "tfacc-wpapsk" + network_id = unifi_network.test.id + passphrase = "12345678" + ap_group_ids = [data.unifi_ap_group.default.id] + user_group_id = data.unifi_user_group.default.id + security = "wpapsk" + no2ghz_oui = false multicast_enhance = true } -`, vlanID) +`, subnet, vlan) } -func testAccWLANConfig_uapsd(vlanID int) string { +func testAccWLANConfig_uapsd(subnet *net.IPNet, vlan int) string { return fmt.Sprintf(` -data "unifi_ap_group" "default" { -} +data "unifi_ap_group" "default" {} -data "unifi_user_group" "default" { -} +data "unifi_user_group" "default" {} resource "unifi_network" "test" { name = "tfacc" purpose = "corporate" - - subnet = cidrsubnet("10.0.0.0/8", 6, %[1]d) - vlan_id = %[1]d + subnet = "%[1]s" + vlan_id = %[2]d } resource "unifi_wlan" "test" { @@ -652,23 +626,20 @@ resource "unifi_wlan" "test" { security = "wpapsk" uapsd = true } -`, vlanID) +`, subnet, vlan) } -func testAccWLANConfig_wpa3(vlanID int, wpa3Transition bool, pmf string) string { +func testAccWLANConfig_wpa3(subnet *net.IPNet, vlan int, wpa3Transition bool, pmf string) string { return fmt.Sprintf(` -data "unifi_ap_group" "default" { -} +data "unifi_ap_group" "default" {} -data "unifi_user_group" "default" { -} +data "unifi_user_group" "default" {} resource "unifi_network" "test" { name = "tfacc" purpose = "corporate" - - subnet = cidrsubnet("10.0.0.0/8", 6, %[1]d) - vlan_id = %[1]d + subnet = "%[1]s" + vlan_id = %[2]d } resource "unifi_wlan" "test" { @@ -680,26 +651,23 @@ resource "unifi_wlan" "test" { security = "wpapsk" wpa3_support = true - wpa3_transition = %[2]t - pmf_mode = %[3]q + wpa3_transition = %[3]t + pmf_mode = %[4]q } -`, vlanID, wpa3Transition, pmf) +`, subnet, vlan, wpa3Transition, pmf) } -func testAccWLANConfig_minimum_data_rate(vlanID int, min2g int, min5g int) string { +func testAccWLANConfig_minimum_data_rate(subnet *net.IPNet, vlan int, min2g int, min5g int) string { return fmt.Sprintf(` -data "unifi_ap_group" "default" { -} +data "unifi_ap_group" "default" {} -data "unifi_user_group" "default" { -} +data "unifi_user_group" "default" {} resource "unifi_network" "test" { name = "tfacc" purpose = "corporate" - - subnet = cidrsubnet("10.0.0.0/8", 6, %[1]d) - vlan_id = %[1]d + subnet = "%[1]s" + vlan_id = %[2]d } resource "unifi_wlan" "test" { @@ -712,8 +680,8 @@ resource "unifi_wlan" "test" { multicast_enhance = true - minimum_data_rate_2g_kbps = %[2]d - minimum_data_rate_5g_kbps = %[3]d + minimum_data_rate_2g_kbps = %[3]d + minimum_data_rate_5g_kbps = %[4]d } -`, vlanID, min2g, min5g) +`, subnet, vlan, min2g, min5g) }