From a4e10637d7ddf1e5c582e62e91e4f45ade4c4d00 Mon Sep 17 00:00:00 2001 From: Michael Dokolin Date: Thu, 28 Dec 2023 08:52:12 +0100 Subject: [PATCH] feat: Add WiFi CAP resource --- .../resources/routeros_wifi_cap/import.sh | 1 + .../resources/routeros_wifi_cap/resource.tf | 4 + routeros/provider.go | 1 + routeros/resource_wifi_cap.go | 105 ++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 examples/resources/routeros_wifi_cap/import.sh create mode 100644 examples/resources/routeros_wifi_cap/resource.tf create mode 100644 routeros/resource_wifi_cap.go diff --git a/examples/resources/routeros_wifi_cap/import.sh b/examples/resources/routeros_wifi_cap/import.sh new file mode 100644 index 00000000..6d5b35bd --- /dev/null +++ b/examples/resources/routeros_wifi_cap/import.sh @@ -0,0 +1 @@ +terraform import routeros_wifi_cap.settings . diff --git a/examples/resources/routeros_wifi_cap/resource.tf b/examples/resources/routeros_wifi_cap/resource.tf new file mode 100644 index 00000000..727cf8d2 --- /dev/null +++ b/examples/resources/routeros_wifi_cap/resource.tf @@ -0,0 +1,4 @@ +resource "routeros_wifi_cap" "settings" { + enabled = true + discovery_interfaces = ["bridge1"] +} diff --git a/routeros/provider.go b/routeros/provider.go index 4aa3988f..b416be4c 100644 --- a/routeros/provider.go +++ b/routeros/provider.go @@ -221,6 +221,7 @@ func Provider() *schema.Provider { // WiFi "routeros_wifi_aaa": ResourceWifiAaa(), "routeros_wifi_access_list": ResourceWifiAccessList(), + "routeros_wifi_cap": ResourceWifiCap(), "routeros_wifi_capsman": ResourceWifiCapsman(), "routeros_wifi_channel": ResourceWifiChannel(), "routeros_wifi_configuration": ResourceWifiConfiguration(), diff --git a/routeros/resource_wifi_cap.go b/routeros/resource_wifi_cap.go new file mode 100644 index 00000000..c6aee38d --- /dev/null +++ b/routeros/resource_wifi_cap.go @@ -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" +) + +/* +{ + "caps-man-addresses": "192.168.88.1", + "caps-man-certificate-common-names": "CAPsMAN-0000000", + "caps-man-names": "router", + "certificate": "request", + "discovery-interfaces": "lan", + "enabled": "no", + "lock-to-caps-man": "true", + "slaves-datapath": "lan", + "slaves-static": "true" +} +*/ + +// https://help.mikrotik.com/docs/display/ROS/WiFi#WiFi-CAPconfiguration +func ResourceWifiCap() *schema.Resource { + resSchema := map[string]*schema.Schema{ + MetaResourcePath: PropResourcePath("/interface/wifi/cap"), + MetaId: PropId(Name), + + "caps_man_addresses": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validation.IsIPAddress, + }, + Description: "List of Manager IP addresses that CAP will attempt to contact during discovery.", + }, + "caps_man_certificate_common_names": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Description: "List of manager certificate common names that CAP will connect to.", + }, + "caps_man_names": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Description: "An ordered list of CAPs Manager names that the CAP will connect to.", + }, + "certificate": { + Type: schema.TypeString, + Optional: true, + Description: "Certificate to use for authentication.", + }, + "discovery_interfaces": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Description: "List of interfaces over which CAP should attempt to discover CAPs Manager.", + }, + "enabled": { + Type: schema.TypeBool, + Optional: true, + Description: "Disable or enable the CAP functionality.", + }, + "lock_to_caps_man": { + Type: schema.TypeBool, + Optional: true, + Description: "Lock CAP to the first CAPsMAN it connects to.", + }, + "locked_caps_man_common_name": { + Type: schema.TypeString, + Computed: true, + Description: "Common name of the CAPsMAN that the CAP is locked to.", + }, + "requested_certificate": { + Type: schema.TypeString, + Computed: true, + Description: "Requested certificate.", + }, + "slaves_datapath": { + Type: schema.TypeString, + Optional: true, + Description: "Name of the bridge interface the CAP will be added to.", + }, + "slaves_static": { + Type: schema.TypeBool, + Optional: true, + Description: "An option that creates static virtual interfaces.", + }, + } + + return &schema.Resource{ + Description: `*This resource requires a minimum version of RouterOS 7.13.*`, + CreateContext: DefaultSystemCreate(resSchema), + ReadContext: DefaultSystemRead(resSchema), + UpdateContext: DefaultSystemUpdate(resSchema), + DeleteContext: DefaultSystemDelete(resSchema), + + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Schema: resSchema, + } +}