From 3fd1f34b040ee1e1eacce246a221a092315b8aea Mon Sep 17 00:00:00 2001 From: Michael Dokolin Date: Fri, 8 Dec 2023 08:43:25 +0100 Subject: [PATCH] feat: Add WiFi channel resource --- .../resources/routeros_wifi_channel/import.sh | 3 + .../routeros_wifi_channel/resource.tf | 8 ++ routeros/provider.go | 9 +-- routeros/resource_wifi_channel.go | 76 +++++++++++++++++++ 4 files changed, 90 insertions(+), 6 deletions(-) create mode 100644 examples/resources/routeros_wifi_channel/import.sh create mode 100644 examples/resources/routeros_wifi_channel/resource.tf create mode 100644 routeros/resource_wifi_channel.go diff --git a/examples/resources/routeros_wifi_channel/import.sh b/examples/resources/routeros_wifi_channel/import.sh new file mode 100644 index 00000000..594d84e5 --- /dev/null +++ b/examples/resources/routeros_wifi_channel/import.sh @@ -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' diff --git a/examples/resources/routeros_wifi_channel/resource.tf b/examples/resources/routeros_wifi_channel/resource.tf new file mode 100644 index 00000000..07ba3e8d --- /dev/null +++ b/examples/resources/routeros_wifi_channel/resource.tf @@ -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" +} diff --git a/routeros/provider.go b/routeros/provider.go index f9434b7c..a75e8709 100644 --- a/routeros/provider.go +++ b/routeros/provider.go @@ -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(), @@ -208,6 +203,7 @@ func Provider() *schema.Provider { // Helpers "routeros_wireguard_keys": ResourceWireguardKeys(), + "routeros_move_items": ResourceMoveItems(), // User Manager "routeros_user_manager_advanced": ResourceUserManagerAdvanced(), @@ -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(), diff --git a/routeros/resource_wifi_channel.go b/routeros/resource_wifi_channel.go new file mode 100644 index 00000000..be8546d5 --- /dev/null +++ b/routeros/resource_wifi_channel.go @@ -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: `*This resource requires a minimum version of RouterOS 7.13.*`, + CreateContext: DefaultCreate(resSchema), + ReadContext: DefaultRead(resSchema), + UpdateContext: DefaultUpdate(resSchema), + DeleteContext: DefaultDelete(resSchema), + + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Schema: resSchema, + } +}