Skip to content

Commit

Permalink
Add PMF mode support to unifi_wlan
Browse files Browse the repository at this point in the history
  • Loading branch information
paultyng committed Sep 16, 2021
1 parent 680b481 commit 2ebf690
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 14 deletions.
4 changes: 3 additions & 1 deletion docs/resources/wlan.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ resource "unifi_wlan" "wifi" {
# enable WPA2/WPA3 support
wpa3_support = true
wpa3_transition = true
pmf_mode = "optional"
network_id = unifi_network.vlan.id
ap_group_ids = [data.unifi_ap_group.default.id]
Expand Down Expand Up @@ -73,12 +74,13 @@ resource "unifi_wlan" "wifi" {
- **network_id** (String) ID of the network for this SSID
- **no2ghz_oui** (Boolean) Connect high performance clients to 5 GHz only Defaults to `true`.
- **passphrase** (String, Sensitive) The passphrase for the network, this is only required if `security` is not set to `open`.
- **pmf_mode** (String) Enable Protected Management Frames. This cannot be disabled if using WPA 3. Valid values are `required`, `optional` and `disabled`. Defaults to `disabled`.
- **radius_profile_id** (String) ID of the RADIUS profile to use when security `wpaeap`. You can query this via the `unifi_radius_profile` data source.
- **schedule** (Block List) Start and stop schedules for the WLAN (see [below for nested schema](#nestedblock--schedule))
- **site** (String) The name of the site to associate the wlan with.
- **uapsd** (Boolean) Enable Unscheduled Automatic Power Save Delivery Defaults to `false`.
- **wlan_band** (String) Radio band your WiFi network will use.
- **wpa3_support** (Boolean) Enable WPA 3 support (security must be `wpapsk`).
- **wpa3_support** (Boolean) Enable WPA 3 support (security must be `wpapsk` and PMF must be turned on).
- **wpa3_transition** (Boolean) Enable WPA 3 and WPA 2 support (security must be `wpapsk` and `wpa3_support` must be true).

### Read-Only
Expand Down
1 change: 1 addition & 0 deletions examples/resources/unifi_wlan/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ resource "unifi_wlan" "wifi" {
# enable WPA2/WPA3 support
wpa3_support = true
wpa3_transition = true
pmf_mode = "optional"

network_id = unifi_network.vlan.id
ap_group_ids = [data.unifi_ap_group.default.id]
Expand Down
19 changes: 17 additions & 2 deletions internal/provider/resource_wlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func resourceWLAN() *schema.Resource {
ValidateFunc: validation.StringInSlice([]string{"wpapsk", "wpaeap", "open"}, false),
},
"wpa3_support": {
Description: "Enable WPA 3 support (security must be `wpapsk`).",
Description: "Enable WPA 3 support (security must be `wpapsk` and PMF must be turned on).",
Type: schema.TypeBool,
Optional: true,
},
Expand All @@ -68,6 +68,13 @@ func resourceWLAN() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
},
"pmf_mode": {
Description: "Enable Protected Management Frames. This cannot be disabled if using WPA 3. Valid values are `required`, `optional` and `disabled`.",
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"required", "optional", "disabled"}, false),
Default: "disabled",
},
"passphrase": {
Description: "The passphrase for the network, this is only required if `security` is not set to `open`.",
Type: schema.TypeString,
Expand Down Expand Up @@ -216,6 +223,7 @@ func resourceWLANGetResourceData(d *schema.ResourceData, meta interface{}) (*uni
passphrase = ""
}

pmf := d.Get("pmf_mode").(string)
wpa3 := d.Get("wpa3_support").(bool)
wpa3Transition := d.Get("wpa3_transition").(bool)
switch security {
Expand All @@ -232,6 +240,12 @@ func resourceWLANGetResourceData(d *schema.ResourceData, meta interface{}) (*uni
}
}

if wpa3Transition && pmf == "disabled" {
return nil, fmt.Errorf("WPA 3 transition mode requires pmf_mode to be turned on.")
} else if wpa3 && !wpa3Transition && pmf != "required" {
return nil, fmt.Errorf("For WPA 3 you must set pmf_mode to required.")
}

macFilterEnabled := d.Get("mac_filter_enabled").(bool)
macFilterList, err := setToStringSlice(d.Get("mac_filter_list").(*schema.Set))
if err != nil {
Expand Down Expand Up @@ -274,6 +288,7 @@ func resourceWLANGetResourceData(d *schema.ResourceData, meta interface{}) (*uni
Schedule: schedule,
ScheduleEnabled: len(schedule) > 0,
WLANBand: wlanBand,
PMFMode: pmf,

// TODO: add to schema
WPAEnc: "ccmp",
Expand Down Expand Up @@ -371,7 +386,7 @@ func resourceWLANSetResourceData(resp *unifi.WLAN, d *schema.ResourceData, meta
d.Set("uapsd", resp.UapsdEnabled)
d.Set("ap_group_ids", apGroupIDs)
d.Set("network_id", resp.NetworkID)

d.Set("pmf_mode", resp.PMFMode)
if resp.MinrateNgEnabled {
d.Set("minimum_data_rate_2g_kbps", resp.MinrateNgDataRateKbps)
} else {
Expand Down
40 changes: 29 additions & 11 deletions internal/provider/resource_wlan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestAccWLAN_wpapsk(t *testing.T) {
},
Steps: []resource.TestStep{
{
Config: testAccWLANConfig_wpapsk(vlanID),
Config: testAccWLANConfig_wpapsk(vlanID, "disabled"),
Check: resource.ComposeTestCheckFunc(
// testCheckNetworkExists(t, "name"),
),
Expand Down Expand Up @@ -103,7 +103,7 @@ func TestAccWLAN_open(t *testing.T) {
})
}

func TestAccWLAN_change_security(t *testing.T) {
func TestAccWLAN_change_security_and_pmf(t *testing.T) {
vlanID := getTestVLAN(t)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
Expand All @@ -119,7 +119,7 @@ func TestAccWLAN_change_security(t *testing.T) {
},
Steps: []resource.TestStep{
{
Config: testAccWLANConfig_wpapsk(vlanID),
Config: testAccWLANConfig_wpapsk(vlanID, "disabled"),
Check: resource.ComposeTestCheckFunc(
// testCheckNetworkExists(t, "name"),
),
Expand All @@ -133,11 +133,26 @@ func TestAccWLAN_change_security(t *testing.T) {
},
importStep("unifi_wlan.test"),
{
Config: testAccWLANConfig_wpapsk(vlanID),
Config: testAccWLANConfig_wpapsk(vlanID, "optional"),
Check: resource.ComposeTestCheckFunc(
// testCheckNetworkExists(t, "name"),
),
},
importStep("unifi_wlan.test"),
{
Config: testAccWLANConfig_wpapsk(vlanID, "required"),
Check: resource.ComposeTestCheckFunc(
// testCheckNetworkExists(t, "name"),
),
},
importStep("unifi_wlan.test"),
{
Config: testAccWLANConfig_wpapsk(vlanID, "disabled"),
Check: resource.ComposeTestCheckFunc(
// testCheckNetworkExists(t, "name"),
),
},
importStep("unifi_wlan.test"),
},
})
}
Expand Down Expand Up @@ -294,21 +309,21 @@ func TestAccWLAN_wpa3(t *testing.T) {
},
Steps: []resource.TestStep{
{
Config: testAccWLANConfig_wpa3(vlanID, false),
Config: testAccWLANConfig_wpa3(vlanID, false, "required"),
Check: resource.ComposeTestCheckFunc(
// testCheckNetworkExists(t, "name"),
),
},
importStep("unifi_wlan.test"),
{
Config: testAccWLANConfig_wpa3(vlanID, true),
Config: testAccWLANConfig_wpa3(vlanID, true, "optional"),
Check: resource.ComposeTestCheckFunc(
// testCheckNetworkExists(t, "name"),
),
},
importStep("unifi_wlan.test"),
{
Config: testAccWLANConfig_wpa3(vlanID, false),
Config: testAccWLANConfig_wpa3(vlanID, false, "required"),
Check: resource.ComposeTestCheckFunc(
// testCheckNetworkExists(t, "name"),
),
Expand Down Expand Up @@ -365,7 +380,7 @@ func TestAccWLAN_minimum_data_rate(t *testing.T) {
})
}

func testAccWLANConfig_wpapsk(vlanID int) string {
func testAccWLANConfig_wpapsk(vlanID int, pmf string) string {
return fmt.Sprintf(`
data "unifi_ap_group" "default" {
}
Expand All @@ -390,8 +405,10 @@ resource "unifi_wlan" "test" {
security = "wpapsk"
multicast_enhance = true
pmf_mode = %[2]q
}
`, vlanID)
`, vlanID, pmf)
}

func testAccWLANConfig_wpaeap(vlanID int) string {
Expand Down Expand Up @@ -608,7 +625,7 @@ resource "unifi_wlan" "test" {
`, vlanID)
}

func testAccWLANConfig_wpa3(vlanID int, wpa3Transition bool) string {
func testAccWLANConfig_wpa3(vlanID int, wpa3Transition bool, pmf string) string {
return fmt.Sprintf(`
data "unifi_ap_group" "default" {
}
Expand All @@ -634,8 +651,9 @@ resource "unifi_wlan" "test" {
wpa3_support = true
wpa3_transition = %[2]t
pmf_mode = %[3]q
}
`, vlanID, wpa3Transition)
`, vlanID, wpa3Transition, pmf)
}

func testAccWLANConfig_minimum_data_rate(vlanID int, min2g int, min5g int) string {
Expand Down

0 comments on commit 2ebf690

Please sign in to comment.