Add support for mDNS on network resource (#292)
* Add support for mDNS on network resource Signed-off-by: Xabier Larrakoetxea <me@slok.dev> * Add mDSN network tests Signed-off-by: Xabier Larrakoetxea <me@slok.dev> --------- Signed-off-by: Xabier Larrakoetxea <me@slok.dev>
This commit is contained in:
committed by
GitHub
parent
81c357b3a5
commit
dc95eceb2e
@@ -64,6 +64,7 @@ data "unifi_network" "my_network" {
|
|||||||
- `ipv6_ra_priority` (String) IPv6 router advertisement priority. Must be one of either `high`, `medium`, or `low`
|
- `ipv6_ra_priority` (String) IPv6 router advertisement priority. Must be one of either `high`, `medium`, or `low`
|
||||||
- `ipv6_ra_valid_lifetime` (Number) Total lifetime in which the address can be used. Must be equal to or greater than `ipv6_ra_preferred_lifetime`.
|
- `ipv6_ra_valid_lifetime` (Number) Total lifetime in which the address can be used. Must be equal to or greater than `ipv6_ra_preferred_lifetime`.
|
||||||
- `ipv6_static_subnet` (String) Specifies the static IPv6 subnet (when ipv6_interface_type is 'static').
|
- `ipv6_static_subnet` (String) Specifies the static IPv6 subnet (when ipv6_interface_type is 'static').
|
||||||
|
- `multicast_dns` (Boolean) Specifies whether Multicast DNS (mDNS) is enabled or not on the network (Controller >=v7).
|
||||||
- `network_group` (String) The group of the network.
|
- `network_group` (String) The group of the network.
|
||||||
- `purpose` (String) The purpose of the network. One of `corporate`, `guest`, `wan`, or `vlan-only`.
|
- `purpose` (String) The purpose of the network. One of `corporate`, `guest`, `wan`, or `vlan-only`.
|
||||||
- `subnet` (String) The subnet of the network (CIDR address).
|
- `subnet` (String) The subnet of the network (CIDR address).
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ resource "unifi_network" "wan" {
|
|||||||
- `ipv6_ra_priority` (String) IPv6 router advertisement priority. Must be one of either `high`, `medium`, or `low`
|
- `ipv6_ra_priority` (String) IPv6 router advertisement priority. Must be one of either `high`, `medium`, or `low`
|
||||||
- `ipv6_ra_valid_lifetime` (Number) Total lifetime in which the address can be used. Must be equal to or greater than `ipv6_ra_preferred_lifetime`. Defaults to `86400`.
|
- `ipv6_ra_valid_lifetime` (Number) Total lifetime in which the address can be used. Must be equal to or greater than `ipv6_ra_preferred_lifetime`. Defaults to `86400`.
|
||||||
- `ipv6_static_subnet` (String) Specifies the static IPv6 subnet when `ipv6_interface_type` is 'static'.
|
- `ipv6_static_subnet` (String) Specifies the static IPv6 subnet when `ipv6_interface_type` is 'static'.
|
||||||
|
- `multicast_dns` (Boolean) Specifies whether Multicast DNS (mDNS) is enabled or not on the network (Controller >=v7).
|
||||||
- `network_group` (String) The group of the network. Defaults to `LAN`.
|
- `network_group` (String) The group of the network. Defaults to `LAN`.
|
||||||
- `site` (String) The name of the site to associate the network with.
|
- `site` (String) The name of the site to associate the network with.
|
||||||
- `subnet` (String) The subnet of the network. Must be a valid CIDR address.
|
- `subnet` (String) The subnet of the network. Must be a valid CIDR address.
|
||||||
|
|||||||
@@ -196,6 +196,11 @@ func dataNetwork() *schema.Resource {
|
|||||||
Type: schema.TypeInt,
|
Type: schema.TypeInt,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
|
"multicast_dns": {
|
||||||
|
Description: "Specifies whether Multicast DNS (mDNS) is enabled or not on the network (Controller >=v7).",
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Computed: true,
|
||||||
|
},
|
||||||
"wan_ip": {
|
"wan_ip": {
|
||||||
Description: "The IPv4 address of the WAN.",
|
Description: "The IPv4 address of the WAN.",
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
@@ -324,6 +329,7 @@ func dataNetworkRead(ctx context.Context, d *schema.ResourceData, meta interface
|
|||||||
d.Set("vlan_id", n.VLAN)
|
d.Set("vlan_id", n.VLAN)
|
||||||
d.Set("subnet", cidrZeroBased(n.IPSubnet))
|
d.Set("subnet", cidrZeroBased(n.IPSubnet))
|
||||||
d.Set("network_group", n.NetworkGroup)
|
d.Set("network_group", n.NetworkGroup)
|
||||||
|
d.Set("dhcp_dns", dhcpDNS)
|
||||||
d.Set("dhcp_start", n.DHCPDStart)
|
d.Set("dhcp_start", n.DHCPDStart)
|
||||||
d.Set("dhcp_stop", n.DHCPDStop)
|
d.Set("dhcp_stop", n.DHCPDStop)
|
||||||
d.Set("dhcp_enabled", n.DHCPDEnabled)
|
d.Set("dhcp_enabled", n.DHCPDEnabled)
|
||||||
@@ -333,12 +339,12 @@ func dataNetworkRead(ctx context.Context, d *schema.ResourceData, meta interface
|
|||||||
d.Set("dhcpd_boot_filename", n.DHCPDBootFilename)
|
d.Set("dhcpd_boot_filename", n.DHCPDBootFilename)
|
||||||
d.Set("domain_name", n.DomainName)
|
d.Set("domain_name", n.DomainName)
|
||||||
d.Set("igmp_snooping", n.IGMPSnooping)
|
d.Set("igmp_snooping", n.IGMPSnooping)
|
||||||
d.Set("dhcp_dns", dhcpDNS)
|
|
||||||
d.Set("ipv6_interface_type", n.IPV6InterfaceType)
|
d.Set("ipv6_interface_type", n.IPV6InterfaceType)
|
||||||
d.Set("ipv6_static_subnet", n.IPV6Subnet)
|
d.Set("ipv6_static_subnet", n.IPV6Subnet)
|
||||||
d.Set("ipv6_pd_interface", n.IPV6PDInterface)
|
d.Set("ipv6_pd_interface", n.IPV6PDInterface)
|
||||||
d.Set("ipv6_pd_prefixid", n.IPV6PDPrefixid)
|
d.Set("ipv6_pd_prefixid", n.IPV6PDPrefixid)
|
||||||
d.Set("ipv6_ra_enable", n.IPV6RaEnabled)
|
d.Set("ipv6_ra_enable", n.IPV6RaEnabled)
|
||||||
|
d.Set("multicast_dns", n.MdnsEnabled)
|
||||||
d.Set("wan_ip", n.WANIP)
|
d.Set("wan_ip", n.WANIP)
|
||||||
d.Set("wan_netmask", n.WANNetmask)
|
d.Set("wan_netmask", n.WANNetmask)
|
||||||
d.Set("wan_gateway", n.WANGateway)
|
d.Set("wan_gateway", n.WANGateway)
|
||||||
|
|||||||
@@ -277,6 +277,11 @@ func resourceNetwork() *schema.Resource {
|
|||||||
Optional: true,
|
Optional: true,
|
||||||
Default: 86400,
|
Default: 86400,
|
||||||
},
|
},
|
||||||
|
"multicast_dns": {
|
||||||
|
Description: "Specifies whether Multicast DNS (mDNS) is enabled or not on the network (Controller >=v7).",
|
||||||
|
Type: schema.TypeBool,
|
||||||
|
Optional: true,
|
||||||
|
},
|
||||||
"wan_ip": {
|
"wan_ip": {
|
||||||
Description: "The IPv4 address of the WAN.",
|
Description: "The IPv4 address of the WAN.",
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
@@ -425,6 +430,7 @@ func resourceNetworkGetResourceData(d *schema.ResourceData, meta interface{}) (*
|
|||||||
DHCPRelayEnabled: d.Get("dhcp_relay_enabled").(bool),
|
DHCPRelayEnabled: d.Get("dhcp_relay_enabled").(bool),
|
||||||
DomainName: d.Get("domain_name").(string),
|
DomainName: d.Get("domain_name").(string),
|
||||||
IGMPSnooping: d.Get("igmp_snooping").(bool),
|
IGMPSnooping: d.Get("igmp_snooping").(bool),
|
||||||
|
MdnsEnabled: d.Get("multicast_dns").(bool),
|
||||||
|
|
||||||
DHCPDDNSEnabled: len(dhcpDNS) > 0,
|
DHCPDDNSEnabled: len(dhcpDNS) > 0,
|
||||||
// this is kinda hacky but ¯\_(ツ)_/¯
|
// this is kinda hacky but ¯\_(ツ)_/¯
|
||||||
@@ -591,6 +597,7 @@ func resourceNetworkSetResourceData(resp *unifi.Network, d *schema.ResourceData,
|
|||||||
d.Set("ipv6_ra_priority", resp.IPV6RaPriority)
|
d.Set("ipv6_ra_priority", resp.IPV6RaPriority)
|
||||||
d.Set("ipv6_ra_valid_lifetime", resp.IPV6RaValidLifetime)
|
d.Set("ipv6_ra_valid_lifetime", resp.IPV6RaValidLifetime)
|
||||||
d.Set("ipv6_static_subnet", resp.IPV6Subnet)
|
d.Set("ipv6_static_subnet", resp.IPV6Subnet)
|
||||||
|
d.Set("multicast_dns", resp.MdnsEnabled)
|
||||||
d.Set("wan_dhcp_v6_pd_size", resp.WANDHCPv6PDSize)
|
d.Set("wan_dhcp_v6_pd_size", resp.WANDHCPv6PDSize)
|
||||||
d.Set("wan_dns", wanDNS)
|
d.Set("wan_dns", wanDNS)
|
||||||
d.Set("wan_egress_qos", resp.WANEgressQOS)
|
d.Set("wan_egress_qos", resp.WANEgressQOS)
|
||||||
|
|||||||
@@ -403,6 +403,36 @@ func TestAccNetwork_vlanOnly(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccNetwork_mdns(t *testing.T) {
|
||||||
|
name := acctest.RandomWithPrefix("tfacc")
|
||||||
|
vlanID := getTestVLAN(t)
|
||||||
|
|
||||||
|
resource.ParallelTest(t, resource.TestCase{
|
||||||
|
PreCheck: func() {
|
||||||
|
preCheck(t)
|
||||||
|
preCheckMinVersion(t, controllerV7)
|
||||||
|
},
|
||||||
|
ProviderFactories: providerFactories,
|
||||||
|
// TODO: CheckDestroy: ,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: testAccNetworkConfigMDNS(name, vlanID, true),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
resource.TestCheckResourceAttr("unifi_network.test", "multicast_dns", "true"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
importStep("unifi_network.test"),
|
||||||
|
{
|
||||||
|
Config: testAccNetworkConfigMDNS(name, vlanID, false),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
resource.TestCheckResourceAttr("unifi_network.test", "multicast_dns", "false"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
importStep("unifi_network.test"),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: ipv6 prefix delegation test
|
// TODO: ipv6 prefix delegation test
|
||||||
|
|
||||||
func quoteStrings(src []string) []string {
|
func quoteStrings(src []string) []string {
|
||||||
@@ -648,3 +678,16 @@ resource "unifi_network" "test" {
|
|||||||
}
|
}
|
||||||
`, name, subnet, vlan, gatewayIP, dhcpdV6Start, dhcpdV6Stop, strings.Join(quoteStrings(dhcpV6DNS), ","))
|
`, name, subnet, vlan, gatewayIP, dhcpdV6Start, dhcpdV6Stop, strings.Join(quoteStrings(dhcpV6DNS), ","))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testAccNetworkConfigMDNS(name string, vlan int, mdns bool) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
resource "unifi_network" "test" {
|
||||||
|
name = "%[1]s"
|
||||||
|
purpose = "corporate"
|
||||||
|
subnet = cidrsubnet("10.0.0.0/8", 6, %[2]d)
|
||||||
|
vlan_id = %[2]d
|
||||||
|
|
||||||
|
multicast_dns = %[3]t
|
||||||
|
}
|
||||||
|
`, name, vlan, mdns)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user