Skip to content

Commit

Permalink
feat: Add WiFi channel resource
Browse files Browse the repository at this point in the history
  • Loading branch information
dokmic authored and vaerh committed Jan 15, 2024
1 parent 6544f3c commit 3fd1f34
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 6 deletions.
3 changes: 3 additions & 0 deletions examples/resources/routeros_wifi_channel/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/channel get [print show-ids]]
terraform import routeros_wifi_channel.channel1 '*1'
8 changes: 8 additions & 0 deletions examples/resources/routeros_wifi_channel/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resource "routeros_wifi_channel" "channel1" {
name = "1"
band = "2ghz-n"
frequency = [2412]
secondary_frequency = ["disabled"]
skip_dfs_channels = "disabled"
width = "20mhz"
}
9 changes: 3 additions & 6 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,6 @@ func Provider() *schema.Provider {
"routeros_identity": ResourceSystemIdentity(),
"routeros_scheduler": ResourceSystemScheduler(),

// TODO: Review whether capsman resources need updating given wifiwave2.
// wifiwave2 is getting support for capsman in 7.8.
// Should we support both legacy capsman _and_ wifiwave2 capsman?
// https://help.mikrotik.com/docs/display/ROS/WifiWave2#WifiWave2-WifiWave2CAPsMAN

// CAPsMAN Objects
"routeros_capsman_access_list": ResourceCapsManAccessList(),
"routeros_capsman_channel": ResourceCapsManChannel(),
Expand Down Expand Up @@ -208,6 +203,7 @@ func Provider() *schema.Provider {

// Helpers
"routeros_wireguard_keys": ResourceWireguardKeys(),
"routeros_move_items": ResourceMoveItems(),

// User Manager
"routeros_user_manager_advanced": ResourceUserManagerAdvanced(),
Expand All @@ -222,7 +218,8 @@ func Provider() *schema.Provider {
"routeros_user_manager_user_group": ResourceUserManagerUserGroup(),
"routeros_user_manager_user_profile": ResourceUserManagerUserProfile(),

"routeros_move_items": ResourceMoveItems(),
// WiFi
"routeros_wifi_channel": ResourceWifiChannel(),
},
DataSourcesMap: map[string]*schema.Resource{
"routeros_firewall": DatasourceFirewall(),
Expand Down
76 changes: 76 additions & 0 deletions routeros/resource_wifi_channel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package routeros

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

/*
{
".id": "*1",
"band": "2ghz-n",
"disabled": "false",
"frequency": "2412",
"name": "channel1",
"secondary-frequency": "disabled",
"skip-dfs-channels": "disabled",
"width": "20mhz"
}
*/

// https://help.mikrotik.com/docs/display/ROS/WiFi#WiFi-Channelproperties
func ResourceWifiChannel() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/interface/wifi/channel"),
MetaId: PropId(Id),

"band": {
Type: schema.TypeString,
Optional: true,
Description: "Frequency band and wireless standard that will be used by the AP. ",
ValidateFunc: validation.StringInSlice([]string{"2ghz-g", "2ghz-n", "2ghz-ax", "5ghz-a", "5ghz-ac", "5ghz-an", "5ghz-ax"}, false),
},
KeyComment: PropCommentRw,
KeyDisabled: PropDisabledRw,
"frequency": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Description: "Channel frequency value or range in MHz on which AP or station will operate.",
},
KeyName: PropName("Name of the channel."),
"secondary_frequency": {
Type: schema.TypeList,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
Description: "Specifies the second frequency that will be used for 80+80MHz configuration. " +
"Set it to `disabled` in order to disable 80+80MHz capability.",
},
"skip_dfs_channels": {
Type: schema.TypeString,
Optional: true,
Description: "An option to avoid using channels on which channel availability check (listening for the presence of radar signals) is required.",
ValidateFunc: validation.StringInSlice([]string{"10min-cac", "all", "disabled"}, false),
},
"width": {
Type: schema.TypeString,
Optional: true,
Description: "Channel width.",
ValidateFunc: validation.StringInSlice([]string{"20mhz", "20/40mhz", "20/40mhz-Ce", "20/40mhz-eC", "20/40/80mhz", "20/40/80+80mhz", "20/40/80/160mhz"}, false),
},
}

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 3fd1f34

Please sign in to comment.