From b9967d9c65f20da871cd6bc60597b49bd9d99d14 Mon Sep 17 00:00:00 2001 From: Vaerh Date: Mon, 2 Sep 2024 08:56:20 +0300 Subject: [PATCH] fix(routeros_capsman_provisioning ): Change attributes type Request #551 changed the type for the `hw_supported_modes`, `ip_address_ranges` and `slave_configurations` attributes. Fixes #551 --- routeros/resource_capsman_provisioning.go | 33 ++++-- routeros/resource_capsman_provisioning_v0.go | 108 +++++++++++++++++++ 2 files changed, 133 insertions(+), 8 deletions(-) create mode 100644 routeros/resource_capsman_provisioning_v0.go diff --git a/routeros/resource_capsman_provisioning.go b/routeros/resource_capsman_provisioning.go index fae04cdc..a7415244 100644 --- a/routeros/resource_capsman_provisioning.go +++ b/routeros/resource_capsman_provisioning.go @@ -45,10 +45,13 @@ func ResourceCapsManProvisioning() *schema.Resource { }, KeyDisabled: PropDisabledRw, "hw_supported_modes": { - Type: schema.TypeString, - Optional: true, - Description: "Match radios by supported wireless modes.", - ValidateFunc: validation.StringInSlice([]string{"a", "a-turbo", "ac", "an", "b", "g", "g-turbo", "gn"}, false), + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + ValidateFunc: validation.StringInSlice([]string{"a", "a-turbo", "ac", "an", "b", "g", "g-turbo", "gn"}, false), + }, + Description: "Match radios by supported wireless modes.", }, "identity_regexp": { Type: schema.TypeString, @@ -56,8 +59,11 @@ func ResourceCapsManProvisioning() *schema.Resource { Description: "Regular expression to match radios by router identity.", }, "ip_address_ranges": { - Type: schema.TypeString, - Optional: true, + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, Description: "Match CAPs with IPs within configured address range.", }, "master_configuration": { @@ -86,8 +92,11 @@ func ResourceCapsManProvisioning() *schema.Resource { ValidateFunc: ValidationMacAddress, }, "slave_configurations": { - Type: schema.TypeString, + Type: schema.TypeSet, 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.", }, @@ -103,6 +112,14 @@ func ResourceCapsManProvisioning() *schema.Resource { StateContext: schema.ImportStatePassthroughContext, }, - Schema: resSchema, + Schema: resSchema, + SchemaVersion: 1, + StateUpgraders: []schema.StateUpgrader{ + { + Type: ResourceCapsManProvisioningV0().CoreConfigSchema().ImpliedType(), + Upgrade: stateMigrationScalarToList("hw_supported_modes", "ip_address_ranges", "slave_configurations"), + Version: 0, + }, + }, } } diff --git a/routeros/resource_capsman_provisioning_v0.go b/routeros/resource_capsman_provisioning_v0.go new file mode 100644 index 00000000..e2ea2bd2 --- /dev/null +++ b/routeros/resource_capsman_provisioning_v0.go @@ -0,0 +1,108 @@ +package routeros + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +/* + { + ".id": "*1", + "action": "none", + "common-name-regexp": "", + "disabled": "false", + "hw-supported-modes": "", + "identity-regexp": "", + "ip-address-ranges": "", + "master-configuration": "cfg1", + "name-format": "cap", + "name-prefix": "", + "radio-mac": "00:00:00:00:00:00", + "slave-configurations": "" + } +*/ + +// https://help.mikrotik.com/docs/display/ROS/CAPsMAN +func ResourceCapsManProvisioningV0() *schema.Resource { + resSchema := map[string]*schema.Schema{ + MetaResourcePath: PropResourcePath("/caps-man/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), + }, + KeyComment: PropCommentRw, + "common_name_regexp": { + Type: schema.TypeString, + Optional: true, + Description: "Regular expression to match radios by common name. Each CAP's common name identifier can be " + + `found under "/caps-man radio" as value "REMOTE-CAP-NAME"`, + }, + KeyDisabled: PropDisabledRw, + "hw_supported_modes": { + Type: schema.TypeString, + Optional: true, + Description: "Match radios by supported wireless modes.", + ValidateFunc: validation.StringInSlice([]string{"a", "a-turbo", "ac", "an", "b", "g", "g-turbo", "gn"}, false), + }, + "identity_regexp": { + Type: schema.TypeString, + Optional: true, + Description: "Regular expression to match radios by router identity.", + }, + "ip_address_ranges": { + Type: schema.TypeString, + Optional: true, + Description: "Match CAPs with IPs within configured address range.", + }, + "master_configuration": { + Type: schema.TypeString, + Required: 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, + Default: "cap", + Description: "Specify the syntax of the CAP interface name creation.", + ValidateFunc: validation.StringInSlice([]string{"cap", "identity", "prefix", "prefix-identity"}, false), + }, + "name_prefix": { + Type: schema.TypeString, + Optional: true, + Description: "Name prefix which can be used in the name-format for creating the CAP interface names.", + }, + "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.TypeString, + Optional: true, + Description: "If action specifies to create interfaces, then a new slave interface for each configuration " + + "profile in this list is created.", + }, + } + + return &schema.Resource{ + CreateContext: DefaultCreate(resSchema), + ReadContext: DefaultRead(resSchema), + UpdateContext: DefaultUpdate(resSchema), + DeleteContext: DefaultDelete(resSchema), + + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Schema: resSchema, + } +}