Skip to content

Commit

Permalink
feat(wifi): Add new resources routeros_interface_w60g, `routeros_in…
Browse files Browse the repository at this point in the history
…terface_w60g_station`

Closes #618
  • Loading branch information
vaerh committed Dec 30, 2024
1 parent 1e0e347 commit 746a223
Show file tree
Hide file tree
Showing 9 changed files with 258 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/resources/routeros_interface_w60g/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#The ID can be found via API or the terminal
#The command for the terminal is -> :put [/interface/w60g get [print show-ids]]
terraform import routeros_interface_w60g.test *3
#Or you can import a resource using one of its attributes
terraform import routeros_interface_w60g.test "name=xxx"
7 changes: 7 additions & 0 deletions examples/resources/routeros_interface_w60g/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "routeros_interface_w60g" "test" {
make = "wlan60-1"
password = "put_your_safe_password_here"
ssid = "put_your_new_ssid_here"
disabled = false
mode = "ap-bridge"
}
5 changes: 5 additions & 0 deletions examples/resources/routeros_interface_w60g_station/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#The ID can be found via API or the terminal
#The command for the terminal is -> :put [/interface/w60g/station get [print show-ids]]
terraform import routeros_interface_w60g_station.test *3
#Or you can import a resource using one of its attributes
terraform import routeros_interface_w60g_station.test "name=xxx"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "routeros_interface_w60g_station" "test" {
name = "wlan60-station-1"
parent = "wlan60-1"
remote-address = "AA:AA:AA:AA:AA:AA"
put-in-bridge = "parent"
}
2 changes: 2 additions & 0 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ func Provider() *schema.Provider {
"routeros_interface_wireless_cap": ResourceInterfaceWirelessCap(),
"routeros_interface_wireless_connect_list": ResourceInterfaceWirelessConnectList(),
"routeros_interface_wireless_security_profiles": ResourceInterfaceWirelessSecurityProfiles(),
"routeros_interface_w60g": ResourceInterfaceW60g(),
"routeros_interface_w60g_station": ResourceInterfaceW60gStation(),

// Aliases for interface objects to retain compatibility between original and fork
"routeros_bridge": ResourceInterfaceBridge(),
Expand Down
145 changes: 145 additions & 0 deletions routeros/resource_interface_w60g.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package routeros

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)

/*
{
".id":"*2",
"arp":"enabled",
"arp-timeout":"auto",
"beamforming-event":"1858",
"default-scan-list":"58320,60480,62640,64800",
"disabled":"false",
"frequency":"60480",
"isolate-stations":"false",
"l2mtu":"1600",
"mac-address":"48:8F:5A:F3:34:E0",
"mode":"ap-bridge",
"mtu":"1500",
"name":"wlan60-1",
"password":"password",
"put-stations-in-bridge":"bridge",
"region":"eu",
"running":"false",
"rx-mpdu-crc-err":"20354232",
"rx-mpdu-crc-ok":"1401642596",
"rx-ppdu":"1403448812",
"ssid":"ptmp01",
"tx-fw-msdu":"52",
"tx-io-msdu":"0",
"tx-mpdu-new":"202533008",
"tx-mpdu-retry":"3570458",
"tx-mpdu-total":"206103466",
"tx-ppdu":"3230579961",
"tx-ppdu-from-q":"2031518609",
"tx-sector":"auto",
"tx-sw-msdu":"202533128"
}
*/

// https://help.mikrotik.com/docs/spaces/ROS/pages/39059501/W60G#W60G-Generalinterfaceproperties
func ResourceInterfaceW60g() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/interface/w60g"),
MetaId: PropId(Id),
MetaSkipFields: PropSkipFields("beamforming_event", "rx_mpdu_crc_err", "rx_mpdu_crc_ok", "rx_ppdu", "tx_fw_msdu",
"tx_io_msdu", "tx_mpdu_new", "tx_mpdu_retry", "tx_mpdu_total", "tx_ppdu", "tx_ppdu_from_q", "tx_sector",
"tx_sw_msdu"),

KeyArp: PropArpRw,
KeyArpTimeout: PropArpTimeoutRw,
KeyComment: PropCommentRw,
KeyDisabled: PropDisabledRw,
"frequency": {
Type: schema.TypeString,
Optional: true,
Description: "Frequency used in communication (Only active on bridge device).",
ValidateFunc: validation.StringInSlice([]string{"58320", "60480", "62640", "64800", "66000", "auto"}, false),
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"isolate_stations": {
Type: schema.TypeBool,
Optional: true,
Description: "Don't allow communication between connected clients (from RouterOS 6.41).",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
KeyL2Mtu: PropL2MtuRw,
KeyMacAddress: PropMacAddressRw("MAC address of the radio interface.", false),
"mdmg_fix": {
Type: schema.TypeBool,
Optional: true,
Description: "Experimental feature working only on wAP60Gx3 devices, providing better point to multi point " +
"stability in some cases.",
},
"mode": {
Type: schema.TypeString,
Optional: true,
Description: "Operation mode.",
ValidateFunc: validation.StringInSlice([]string{"ap-bridge", "bridge", "sniff", "station-bridge"}, false),
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
KeyMtu: PropMtuRw(),
KeyName: PropName("Name of the interface."),
"password": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
Description: "Password used for AES encryption.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"put_stations_in_bridge": {
Type: schema.TypeString,
Optional: true,
Description: "Put newly created station device interfaces in this bridge.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"region": {
Type: schema.TypeBool,
Optional: true,
Description: "Parameter to limit frequency use.",
ValidateFunc: validation.StringInSlice([]string{"asia", "australia", "canada", "china", "eu", "japan", "no-region-set", "usa"}, false),
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
KeyRunning: PropRunningRo,
"scan_list": {
Type: schema.TypeSet,
Optional: true,
Description: "Scan list to limit connectivity over frequencies in station mode.",
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"58320", "60480", "62640", "64800", "66000", "auto"}, false),
},
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"ssid": {
Type: schema.TypeString,
Optional: true,
Description: "SSID (service set identifier) is a name that identifies wireless network (0..32 char).",
ValidateFunc: validation.StringLenBetween(0, 32),
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"tx_sector": {
Type: schema.TypeInt,
Optional: true,
Description: "Disables beamforming and locks to selected radiation pattern.",
ValidateFunc: validation.IntBetween(0, 63),
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
}

return &schema.Resource{
CreateContext: DefaultCreate(resSchema),
ReadContext: DefaultRead(resSchema),
UpdateContext: DefaultUpdate(resSchema),
DeleteContext: DefaultDelete(resSchema),

Importer: &schema.ResourceImporter{
StateContext: ImportStateCustomContext(resSchema),
},

Schema: resSchema,
}
}
70 changes: 70 additions & 0 deletions routeros/resource_interface_w60g_station.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package routeros

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

/*
{
".id":"*8",
"arp":"enabled",
"arp-timeout":"auto",
"beamforming-event":"3042",
"disabled":"false",
"mac-address":"48:8F:5A:F3:34:E0",
"mtu":"1500",
"name":"ptp01",
"parent":"wlan60-1",
"put-in-bridge":"parent",
"remote-address":"48:8F:5A:47:81:9E",
"running":"true"
}
*/

// https://help.mikrotik.com/docs/spaces/ROS/pages/39059501/W60G
func ResourceInterfaceW60gStation() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/interface/w60g/station"),
MetaId: PropId(Id),
MetaSkipFields: PropSkipFields("beamforming_event"),

KeyArp: PropArpRw,
KeyArpTimeout: PropArpTimeoutRw,
KeyDisabled: PropDisabledRw,
KeyMacAddress: PropMacAddressRw("MAC address of the station interface.", false),
KeyMtu: PropMtuRw(),
KeyName: PropName("Name of the interface."),
"parent": {
Type: schema.TypeString,
Required: true,
Description: "Parent interface name.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"put_in_bridge": {
Type: schema.TypeString,
Optional: true,
Description: "Add station device interface to specific bridge.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"remote_address": {
Type: schema.TypeString,
Optional: true,
Description: "MAC address of bridge interface, station is connecting to.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
KeyRunning: PropRunningRo,
}

return &schema.Resource{
CreateContext: DefaultCreate(resSchema),
ReadContext: DefaultRead(resSchema),
UpdateContext: DefaultUpdate(resSchema),
DeleteContext: DefaultDelete(resSchema),

Importer: &schema.ResourceImporter{
StateContext: ImportStateCustomContext(resSchema),
},

Schema: resSchema,
}
}
9 changes: 9 additions & 0 deletions routeros/resource_interface_w60g_station_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package routeros

import (
"testing"
)

func TestAccInterfaceW60gStationTest_basic(t *testing.T) {
t.Log("The test is skipped, the resource is only available on real hardware.")
}
9 changes: 9 additions & 0 deletions routeros/resource_interface_w60g_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package routeros

import (
"testing"
)

func TestAccInterfaceW60gTest_basic(t *testing.T) {
t.Log("The test is skipped, the resource is only available on real hardware.")
}

0 comments on commit 746a223

Please sign in to comment.