Add wan_dns1 and wan_dns2 (#117)

This commit is contained in:
Joshua Spence
2021-03-22 07:27:28 +11:00
committed by GitHub
parent 2694fcb3f5
commit 0409579c68
3 changed files with 28 additions and 4 deletions

View File

@@ -67,6 +67,8 @@ resource "unifi_network" "wan" {
- **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.
- **vlan_id** (Number) The VLAN ID of the network.
- **wan_dns1** (String) Primary DNS server for the WAN.
- **wan_dns2** (String) Secondary DNS server for the WAN.
- **wan_egress_qos** (Number) Specifies the WAN egress quality of service. Defaults to `0`.
- **wan_ip** (String) The IPv4 address of the WAN.
- **wan_networkgroup** (String) Specifies the WAN network group. Must be one of either `WAN`, `WAN2` or `WAN_LTE_FAILOVER`.

View File

@@ -190,6 +190,18 @@ func resourceNetwork() *schema.Resource {
Optional: true,
ValidateFunc: validateWANPassword,
},
"wan_dns1": {
Description: "Primary DNS server for the WAN.",
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.IsIPv4Address,
},
"wan_dns2": {
Description: "Secondary DNS server for the WAN.",
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.IsIPv4Address,
},
},
}
}
@@ -260,6 +272,8 @@ func resourceNetworkGetResourceData(d *schema.ResourceData) (*unifi.Network, err
WANEgressQOS: d.Get("wan_egress_qos").(int),
WANUsername: d.Get("wan_username").(string),
XWANPassword: d.Get("x_wan_password").(string),
WANDNS1: d.Get("wan_dns1").(string),
WANDNS2: d.Get("wan_dns2").(string),
}, nil
}
@@ -319,6 +333,8 @@ func resourceNetworkSetResourceData(resp *unifi.Network, d *schema.ResourceData,
d.Set("wan_egress_qos", resp.WANEgressQOS)
d.Set("wan_username", resp.WANUsername)
d.Set("x_wan_password", resp.XWANPassword)
d.Set("wan_dns1", resp.WANDNS1)
d.Set("wan_dns2", resp.WANDNS2)
return nil
}

View File

@@ -141,7 +141,7 @@ func TestAccNetwork_wan(t *testing.T) {
// TODO: CheckDestroy: ,
Steps: []resource.TestStep{
{
Config: testWanNetworkConfig("WAN", "pppoe", "192.168.1.1", 1, "username", "password"),
Config: testWanNetworkConfig("WAN", "pppoe", "192.168.1.1", 1, "username", "password", "8.8.8.8", "4.4.4.4"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("unifi_network.wan_test", "wan_networkgroup", "WAN"),
resource.TestCheckResourceAttr("unifi_network.wan_test", "wan_type", "pppoe"),
@@ -149,11 +149,13 @@ func TestAccNetwork_wan(t *testing.T) {
resource.TestCheckResourceAttr("unifi_network.wan_test", "wan_egress_qos", "1"),
resource.TestCheckResourceAttr("unifi_network.wan_test", "wan_username", "username"),
resource.TestCheckResourceAttr("unifi_network.wan_test", "x_wan_password", "password"),
resource.TestCheckResourceAttr("unifi_network.wan_test", "wan_dns1", "8.8.8.8"),
resource.TestCheckResourceAttr("unifi_network.wan_test", "wan_dns2", "4.4.4.4"),
),
},
importStep("unifi_network.wan_test"),
{
Config: testWanNetworkConfig("WAN", "pppoe", "192.168.1.1", 1, "username", "password"),
Config: testWanNetworkConfig("WAN", "pppoe", "192.168.1.1", 1, "username", "password", "8.8.8.8", "4.4.4.4"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("unifi_network.wan_test", "wan_networkgroup", "WAN"),
resource.TestCheckResourceAttr("unifi_network.wan_test", "wan_type", "pppoe"),
@@ -161,6 +163,8 @@ func TestAccNetwork_wan(t *testing.T) {
resource.TestCheckResourceAttr("unifi_network.wan_test", "wan_egress_qos", "1"),
resource.TestCheckResourceAttr("unifi_network.wan_test", "wan_username", "username"),
resource.TestCheckResourceAttr("unifi_network.wan_test", "x_wan_password", "password"),
resource.TestCheckResourceAttr("unifi_network.wan_test", "wan_dns1", "8.8.8.8"),
resource.TestCheckResourceAttr("unifi_network.wan_test", "wan_dns2", "4.4.4.4"),
),
},
importStep("unifi_network.wan_test"),
@@ -308,7 +312,7 @@ resource "unifi_network" "test" {
`, vlan, ipv6Type, ipv6Subnet)
}
func testWanNetworkConfig(networkGroup string, wanType string, wanIP string, wanEgressQOS int, wanUsername string, wanPassword string) string {
func testWanNetworkConfig(networkGroup string, wanType string, wanIP string, wanEgressQOS int, wanUsername string, wanPassword string, wanDNS1 string, wanDNS2 string) string {
return fmt.Sprintf(`
resource "unifi_network" "wan_test" {
name = "tfwan"
@@ -319,8 +323,10 @@ resource "unifi_network" "wan_test" {
wan_egress_qos = %d
wan_username = "%s"
x_wan_password = "%s"
wan_dns1 = "%s"
wan_dns2 = "%s"
}
`, networkGroup, wanType, wanIP, wanEgressQOS, wanUsername, wanPassword)
`, networkGroup, wanType, wanIP, wanEgressQOS, wanUsername, wanPassword, wanDNS1, wanDNS2)
}
func testAccNetworkWithSiteConfig(vlan int) string {