Skip to content

Conversation

longranger
Copy link

Description

This PR introduces support for configuring Private Pre-Shared Keys (PPSK) on the unifi_wlan resource. This allows users to define multiple passphrases for a single SSID, with each passphrase potentially assigning clients to a different VLAN/network.

Motivation and Context

PPSK is a valuable Unifi Network Application feature for enhancing network segmentation without proliferating SSIDs. It allows, for example, IoT devices, guest users, and trusted internal users to connect to the same SSID but be isolated on different network segments based on the passphrase they use. This functionality was previously unavailable for management via this Terraform provider.

Implementation Details

The implementation is based on investigation of the Unifi Controller API (tested on version 9.1.120. The key API elements utilized for the unifi_wlan resource are:

  • A boolean flag private_preshared_keys_enabled on the WLAN object.
  • An array private_preshared_keys, where each entry contains:
    • networkconf_id: The _id of the unifi_network for VLAN assignment.
    • password: The passphrase for that specific entry.

The unifi_wlan resource schema has been updated with two new optional attributes:

  • private_preshared_keys_enabled (Boolean): Enables PPSK mode for the WLAN. Defaults to false.
  • private_preshared_key (Block List/Set): A list of blocks, each defining a private pre-shared key. Each block contains:
    • password (String, Required, Sensitive): The actual passphrase.
    • network_id (String, Required): The ID of an existing unifi_network resource to associate with this passphrase.

When private_preshared_keys_enabled is set to true, the top-level x_password attribute for the WLAN is not used and should not be configured, as observed in Unifi UI behavior where the primary PSK is effectively managed within the PPSK list. The provider will ensure these are mutually exclusive or that x_password is ignored when PPSK is active.

This PR also includes an upgrade of the go-unifi library to v1.34.0and necessary adaptations in resource_network.go and resource_port_profile.go to align with changes in the updated library.

How to Test

  1. Ensure you have a Unifi site and at least two unifi_network resources defined (e.g., for VLAN 10 and VLAN 20).

  2. Configure a unifi_wlan resource using the new PPSK attributes:

    resource "unifi_network" "vlan10_net" {
      site    = "default"
      name    = "VLAN10 Network"
      purpose = "vlan-only"
      vlan_id = 10
    }
    
    resource "unifi_network" "vlan20_net" {
      site    = "default"
      name    = "VLAN20 Network"
      purpose = "vlan-only"
      vlan_id = 20
    }
    
    resource "unifi_wlan" "my_ppsk_wifi" {
      site            = "default"
      name            = "MyPPSK-SSID"
      security        = "wpapsk"
    
      private_preshared_keys_enabled = true
      private_preshared_key {
        password   = "SecurePasswordForVLAN10"
        network_id = unifi_network.vlan10_net.id
      }
      private_preshared_key {
        password   = "AnotherSecurePassForVLAN20"
        network_id = unifi_network.vlan20_net.id
      }
      # Example for default network (no VLAN tag for this specific key)
      # private_preshared_key {
      #   password   = "PasswordForDefaultLAN"
      #   network_id = data.unifi_network.default_lan.id # Assuming a data source for default LAN
      # }
    }
  3. Run terraform apply.

  4. Verify in the Unifi Network Application UI that the SSID ("MyPPSK-SSID") is created with "Multiple Passphrases" / PPSK enabled and the specified keys are present and correctly mapped to their respective networks (VLANs).

  5. Test by connecting different client devices to "MyPPSK-SSID" using the different passphrases. Verify that clients receive IP addresses from the correct VLAN subnets and that network traffic is tagged appropriately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant