Skip to content

Commit

Permalink
feat: Add routeros_wifi resource to manage WiFi interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
dokmic authored and vaerh committed Mar 18, 2024
1 parent 93a7495 commit 5f234c4
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/resources/routeros_wifi/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#The ID can be found via API or the terminal
#The command for the terminal is -> :put [/interface/wifi get [print show-ids]]
terraform import routeros_wifi.wifi1 '*1'
6 changes: 6 additions & 0 deletions examples/resources/routeros_wifi/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "routeros_wifi" "wifi1" {
configuration = {
manager = "capsman"
}
name = "wifi1"
}
1 change: 1 addition & 0 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ func Provider() *schema.Provider {
"routeros_user_manager_user_profile": ResourceUserManagerUserProfile(),

// WiFi
"routeros_wifi": ResourceWifi(),
"routeros_wifi_aaa": ResourceWifiAaa(),
"routeros_wifi_access_list": ResourceWifiAccessList(),
"routeros_wifi_cap": ResourceWifiCap(),
Expand Down
163 changes: 163 additions & 0 deletions routeros/resource_wifi.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package routeros

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

/*
{
".about": "mode: AP, SSID: wlan, channel: 2462/n",
".id": "*1",
"arp": "enabled",
"arp-timeout": "auto",
"bound": "true",
"configuration": "cfg1",
"configuration.manager": "capsman",
"configuration.mode": "ap",
"default-name": "wifi1",
"disabled": "false",
"inactive": "false",
"l2mtu": "1560",
"mac-address": "00:00:00:00:00:00",
"master": "true",
"name": "wifi1",
"radio-mac": "00:00:00:00:00:00",
"running": "true",
"security.connect-priority": "0"
}
*/

// https://help.mikrotik.com/docs/display/ROS/WiFi#WiFi-Miscellaneousproperties
// https://help.mikrotik.com/docs/display/ROS/WiFi#WiFi-Read-onlyproperties
func ResourceWifi() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/interface/wifi"),
MetaId: PropId(Id),
MetaTransformSet: PropTransformSet(`"aaa": "aaa.config", "channel": "channel.config", "configuration": "configuration.config",
"datapath": "datapath.config", "interworking": "interworking.config", "security": "security.config", "steering": "steering.config"`),

"aaa": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "AAA inline settings.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
KeyArp: PropArpRw,
KeyArpTimeout: PropArpTimeoutRw,
"bound": {
Type: schema.TypeBool,
Computed: true,
Description: "A flag whether the interface is currently available for the WiFi manager.",
},
"channel": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "Channel inline settings.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"configuration": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "Configuration inline settings.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"datapath": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "Datapath inline settings.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"default_name": {
Type: schema.TypeString,
Computed: true,
Description: "The interface's default name.",
},
KeyDisabled: PropDisabledRw,
"disable_running_check": {
Type: schema.TypeBool,
Optional: true,
Description: "An option to set the running property to true if it is not disabled.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"inactive": {
Type: schema.TypeBool,
Computed: true,
Description: "A flag whether the interface is currently inactive.",
},
"interworking": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "Interworking inline settings.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
KeyL2Mtu: PropL2MtuRw,
"mac_address": {
Type: schema.TypeString,
Description: "MAC address (BSSID) to use for the interface.",
Optional: true,
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"master": {
Type: schema.TypeBool,
Computed: true,
Description: "A flag whether the interface is not a virtual one.",
},
"master_interface": {
Type: schema.TypeString,
Optional: true,
Description: "The corresponding master interface of the virtual one.",
},
"mtu": {
Type: schema.TypeInt,
Optional: true,
Description: "Layer3 maximum transmission unit",
ValidateFunc: validation.IntBetween(32, 2290),
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
KeyName: PropName("Name of the interface."),
"radio_mac": {
Type: schema.TypeString,
Computed: true,
Description: "The MAC address of the associated radio.",
},
"running": {
Type: schema.TypeBool,
Computed: true,
Description: "A flag whether the interface has established a link to another device.",
},
"security": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "Security inline settings.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"steering": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "Steering inline settings.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
}

return &schema.Resource{
Description: `*<span style="color:red">This resource requires a minimum version of RouterOS 7.13.</span>*`,
CreateContext: DefaultCreate(resSchema),
ReadContext: DefaultRead(resSchema),
UpdateContext: DefaultUpdate(resSchema),
DeleteContext: DefaultDelete(resSchema),

Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

Schema: resSchema,
}
}

0 comments on commit 5f234c4

Please sign in to comment.