Skip to content

Commit

Permalink
feat: Add WiFi provisioning 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 e5a213a commit 7a80781
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/resources/routeros_wifi_provisioning/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/provisioning get [print show-ids]]
terraform import routeros_wifi_provisioning.provisioning1 '*1'
14 changes: 14 additions & 0 deletions examples/resources/routeros_wifi_provisioning/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resource "routeros_wifi_configuration" "configuration1" {
country = "Netherlands"
manager = "capsman"
mode = "ap"
name = "configuration1"
ssid = "my-network"
}

resource "routeros_wifi_provisioning" "provisioning1" {
action = "create-enabled"
master_configuration = routeros_wifi_configuration.configuration1.name
name_format = "cap1:"
radio_mac = "00:11:22:33:44:55"
}
1 change: 1 addition & 0 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func Provider() *schema.Provider {
"routeros_wifi_channel": ResourceWifiChannel(),
"routeros_wifi_datapath": ResourceWifiDatapath(),
"routeros_wifi_interworking": ResourceWifiInterworking(),
"routeros_wifi_provisioning": ResourceWifiProvisioning(),
"routeros_wifi_security": ResourceWifiSecurity(),
"routeros_wifi_steering": ResourceWifiSteering(),
},
Expand Down
105 changes: 105 additions & 0 deletions routeros/resource_wifi_provisioning.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package routeros

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

/*
{
".id": "*1",
"action": "create-enabled",
"address-ranges": "192.168.88.1-192.168.88.100,192.168.100.1-192.168.100.100",
"common-name-regexp": "test",
"disabled": "false",
"identity-regexp": "test",
"master-configuration": "cfg1",
"name-format": "cap1:",
"radio-mac": "00:00:00:00:00:00",
"slave-configurations": "cfg1",
"supported-bands": "2ghz-n,2ghz-g"
}
*/

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

"action": {
Type: schema.TypeString,
Optional: true,
Default: "none",
Description: "Provisioning action.",
ValidateFunc: validation.StringInSlice([]string{"create-disabled", "create-enabled",
"create-dynamic-enabled", "none"}, false),
},
"address_ranges": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "Match CAPs by IPs within configured address ranges.",
},
KeyComment: PropCommentRw,
"common_name_regexp": {
Type: schema.TypeString,
Optional: true,
Description: "Regular expression to match radios by common name.",
},
KeyDisabled: PropDisabledRw,
"identity_regexp": {
Type: schema.TypeString,
Optional: true,
Description: "Regular expression to match radios by router identity.",
},
"master_configuration": {
Type: schema.TypeString,
Optional: true,
Description: "If action specifies to create interfaces, then a new master interface with its configuration " +
"set to this configuration profile will be created.",
},
"name_format": {
Type: schema.TypeString,
Optional: true,
Description: "Specify the format of the CAP interface name creation.",
},
"radio_mac": {
Type: schema.TypeString,
Optional: true,
Default: "00:00:00:00:00:00",
Description: "MAC address of radio to be matched, empty MAC (00:00:00:00:00:00) means match all MAC addresses.",
ValidateFunc: ValidationMacAddress,
},
"slave_configurations": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "If action specifies to create interfaces, then a new slave interface for each configuration " +
"profile in this list is created.",
},
"supported_bands": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"2ghz-ax", "2ghz-g", "2ghz-n", "5ghz-a", "5ghz-ac", "5ghz-ax", "5ghz-n"}, false),
},
Description: "Match CAPs by supported modes.",
},
}

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 7a80781

Please sign in to comment.