Skip to content

Commit

Permalink
feat: Update the vlan_ids property in `routeros_interface_bridge_vl…
Browse files Browse the repository at this point in the history
…an` to support multiple values
  • Loading branch information
dokmic committed Jun 17, 2024
1 parent 66ab1d2 commit 3ec3d34
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/resources/interface_bridge_vlan.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## Example Usage
```terraform
resource "routeros_interface_bridge_vlan" "bridge_vlan" {
vlan_ids = "50"
vlan_ids = ["50"]
bridge = "bridge"
tagged = [
"bridge",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "routeros_interface_bridge_vlan" "bridge_vlan" {
vlan_ids = "50"
vlan_ids = ["50"]
bridge = "bridge"
tagged = [
"bridge",
Expand Down
13 changes: 12 additions & 1 deletion routeros/resource_interface_bridge_vlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,11 @@ func ResourceInterfaceBridgeVlan() *schema.Resource {
"separated values. E.g. untagged=ether3,ether4",
},
"vlan_ids": {
Type: schema.TypeString,
Type: schema.TypeSet,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "The list of VLAN IDs for certain port configuration. This setting accepts VLAN ID range " +
"as well as comma separated values. E.g. vlan-ids=100-115,120,122,128-130.",
},
Expand All @@ -96,5 +99,13 @@ func ResourceInterfaceBridgeVlan() *schema.Resource {
},

Schema: resSchema,
SchemaVersion: 1,
StateUpgraders: []schema.StateUpgrader{
{
Type: ResourceInterfaceBridgeVlanV0().CoreConfigSchema().ImpliedType(),
Upgrade: stateMigrationScalarToList("vlan_ids"),
Version: 0,
},
},
}
}
2 changes: 1 addition & 1 deletion routeros/resource_interface_bridge_vlan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ resource "routeros_interface_bridge_vlan" "test_vlan" {
bridge = "bridge"
untagged = ["ether1"]
tagged = ["bridge"]
vlan_ids = 200
vlan_ids = [200]
}
`
Expand Down
100 changes: 100 additions & 0 deletions routeros/resource_interface_bridge_vlan_v0.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package routeros

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

/*
[
{
".id": "*1",
"bridge": "bridge",
"comment": "Management",
"current-tagged": "bridge,ether2,ether3",
"current-untagged": "",
"disabled": "false",
"dynamic": "false",
"tagged": "ether2,ether4,ether5,bridge,ether3",
"untagged": "",
"vlan-ids": "2"
},
{...}
]
*/

// ResourceInterfaceBridgeVlan https://wiki.mikrotik.com/wiki/Manual:Interface/Bridge#Bridge_VLAN_Filtering
func ResourceInterfaceBridgeVlanV0() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/interface/bridge/vlan"),
MetaId: PropId(Id),
MetaSkipFields: PropSkipFields("debug_info"),

"bridge": {
Type: schema.TypeString,
Required: true,
Description: "The bridge interface which the respective VLAN entry is intended for.",
},
KeyComment: PropCommentRw,
"current_tagged": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"current_untagged": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
KeyDisabled: PropDisabledRw,
KeyDynamic: PropDynamicRo,
"mvrp_forbidden": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "Ports that ignore all MRP messages and remains Not Registered (MT), as well as disables applicant from declaring specific VLAN ID (available since RouterOS 7.15).",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"tagged": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "Interface list with a VLAN tag adding action in egress. This setting accepts comma " +
"separated values. E.g. tagged=ether1,ether2.",
},
"untagged": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "Interface list with a VLAN tag removing action in egress. This setting accepts comma " +
"separated values. E.g. untagged=ether3,ether4",
},
"vlan_ids": {
Type: schema.TypeString,
Required: true,
Description: "The list of VLAN IDs for certain port configuration. This setting accepts VLAN ID range " +
"as well as comma separated values. E.g. vlan-ids=100-115,120,122,128-130.",
},
}

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 3ec3d34

Please sign in to comment.