Skip to content

Commit

Permalink
fix(routeros_capsman_provisioning ): Change attributes type
Browse files Browse the repository at this point in the history
Request #551 changed the type for the `hw_supported_modes`, `ip_address_ranges` and  `slave_configurations` attributes.
Fixes #551
  • Loading branch information
vaerh committed Sep 2, 2024
1 parent f9489a2 commit b9967d9
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 8 deletions.
33 changes: 25 additions & 8 deletions routeros/resource_capsman_provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,25 @@ 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,
Optional: true,
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": {
Expand Down Expand Up @@ -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.",
},
Expand All @@ -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,
},
},
}
}
108 changes: 108 additions & 0 deletions routeros/resource_capsman_provisioning_v0.go
Original file line number Diff line number Diff line change
@@ -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,
}
}

0 comments on commit b9967d9

Please sign in to comment.