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
@@ -196,6 +196,11 @@ func dataNetwork() *schema.Resource {
|
||||
Type: schema.TypeInt,
|
||||
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": {
|
||||
Description: "The IPv4 address of the WAN.",
|
||||
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("subnet", cidrZeroBased(n.IPSubnet))
|
||||
d.Set("network_group", n.NetworkGroup)
|
||||
d.Set("dhcp_dns", dhcpDNS)
|
||||
d.Set("dhcp_start", n.DHCPDStart)
|
||||
d.Set("dhcp_stop", n.DHCPDStop)
|
||||
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("domain_name", n.DomainName)
|
||||
d.Set("igmp_snooping", n.IGMPSnooping)
|
||||
d.Set("dhcp_dns", dhcpDNS)
|
||||
d.Set("ipv6_interface_type", n.IPV6InterfaceType)
|
||||
d.Set("ipv6_static_subnet", n.IPV6Subnet)
|
||||
d.Set("ipv6_pd_interface", n.IPV6PDInterface)
|
||||
d.Set("ipv6_pd_prefixid", n.IPV6PDPrefixid)
|
||||
d.Set("ipv6_ra_enable", n.IPV6RaEnabled)
|
||||
d.Set("multicast_dns", n.MdnsEnabled)
|
||||
d.Set("wan_ip", n.WANIP)
|
||||
d.Set("wan_netmask", n.WANNetmask)
|
||||
d.Set("wan_gateway", n.WANGateway)
|
||||
|
||||
@@ -277,6 +277,11 @@ func resourceNetwork() *schema.Resource {
|
||||
Optional: true,
|
||||
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": {
|
||||
Description: "The IPv4 address of the WAN.",
|
||||
Type: schema.TypeString,
|
||||
@@ -425,6 +430,7 @@ func resourceNetworkGetResourceData(d *schema.ResourceData, meta interface{}) (*
|
||||
DHCPRelayEnabled: d.Get("dhcp_relay_enabled").(bool),
|
||||
DomainName: d.Get("domain_name").(string),
|
||||
IGMPSnooping: d.Get("igmp_snooping").(bool),
|
||||
MdnsEnabled: d.Get("multicast_dns").(bool),
|
||||
|
||||
DHCPDDNSEnabled: len(dhcpDNS) > 0,
|
||||
// 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_valid_lifetime", resp.IPV6RaValidLifetime)
|
||||
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_dns", wanDNS)
|
||||
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
|
||||
|
||||
func quoteStrings(src []string) []string {
|
||||
@@ -648,3 +678,16 @@ resource "unifi_network" "test" {
|
||||
}
|
||||
`, 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