Skip to content

Commit

Permalink
Add support for port aggregation
Browse files Browse the repository at this point in the history
Fixes #142
  • Loading branch information
paultyng committed Sep 13, 2021
1 parent be8f77c commit 4446ef0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
9 changes: 9 additions & 0 deletions docs/resources/device.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ resource "unifi_device" "us_24_poe" {
name = "disabled"
port_profile_id = data.unifi_port_profile.disabled.id
}
# port aggregation for ports 11 and 12
port_override {
number = 11
op_mode = "aggregate"
aggregate_num_ports = 2
}
}
```

Expand Down Expand Up @@ -78,7 +85,9 @@ Required:

Optional:

- **aggregate_num_ports** (Number) Number of ports in the aggregate.
- **name** (String) Human-readable name of the port.
- **op_mode** (String) Operating mode of the port, valid values are `switch`, `mirror`, and `aggregate`.
- **port_profile_id** (String) ID of the Port Profile used on this port.


7 changes: 7 additions & 0 deletions examples/resources/unifi_device/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,11 @@ resource "unifi_device" "us_24_poe" {
name = "disabled"
port_profile_id = data.unifi_port_profile.disabled.id
}

# port aggregation for ports 11 and 12
port_override {
number = 11
op_mode = "aggregate"
aggregate_num_ports = 2
}
}
34 changes: 26 additions & 8 deletions internal/provider/resource_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ func resourceDevice() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"op_mode": {
Description: "Operating mode of the port, valid values are `switch`, `mirror`, and `aggregate`.",
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{"switch", "mirror", "aggregate"}, false),
// Default: "switch",
},
"aggregate_num_ports": {
Description: "Number of ports in the aggregate.",
Type: schema.TypeInt,
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -284,21 +296,27 @@ func setFromPortOverrides(pos []unifi.DevicePortOverrides) ([]map[string]interfa
}

func toPortOverride(data map[string]interface{}) (unifi.DevicePortOverrides, error) {
// TODO: error check these?
idx := data["number"].(int)
name := data["name"].(string)
profile_id := data["port_profile_id"].(string)
profileID := data["port_profile_id"].(string)
opMode := data["op_mode"].(string)
aggregateNumPorts := data["aggregate_num_ports"].(int)

return unifi.DevicePortOverrides{
PortIDX: idx,
Name: name,
PortProfileID: profile_id,
PortIDX: idx,
Name: name,
PortProfileID: profileID,
OpMode: opMode,
AggregateNumPorts: aggregateNumPorts,
}, nil
}

func fromPortOverride(po unifi.DevicePortOverrides) (map[string]interface{}, error) {
return map[string]interface{}{
"number": po.PortIDX,
"name": po.Name,
"port_profile_id": po.PortProfileID,
"number": po.PortIDX,
"name": po.Name,
"port_profile_id": po.PortProfileID,
"op_mode": po.OpMode,
"aggregate_num_ports": po.AggregateNumPorts,
}, nil
}

0 comments on commit 4446ef0

Please sign in to comment.