Skip to content

Commit

Permalink
feat(switch): Add support for /interface/ethernet/switch/vlan
Browse files Browse the repository at this point in the history
Fixes #325
  • Loading branch information
vaerh committed Jan 12, 2024
1 parent 1613f5a commit 7463f0e
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 1 deletion.
3 changes: 2 additions & 1 deletion routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ func Provider() *schema.Provider {
"routeros_interface_dot1x_server": ResourceInterfaceDot1xServer(),
"routeros_interface_eoip": ResourceInterfaceEoip(),
"routeros_interface_ethernet_switch": ResourceInterfaceEthernetSwitch(),
"routeros_interface_ethernet_switch_host": ResourceInterfaceEthernetSwitchHost(),
"routeros_interface_ethernet_switch_host": ResourceInterfaceEthernetSwitchHost(),
"routeros_interface_ethernet_switch_port": ResourceInterfaceEthernetSwitchPort(),
"routeros_interface_ethernet_switch_port_isolation": ResourceInterfaceEthernetSwitchPortIsolation(),
"routeros_interface_ethernet_switch_vlan": ResourceInterfaceEthernetSwitchVlan(),
"routeros_interface_gre": ResourceInterfaceGre(),
"routeros_interface_vlan": ResourceInterfaceVlan(),
"routeros_interface_vrrp": ResourceInterfaceVrrp(),
Expand Down
69 changes: 69 additions & 0 deletions routeros/resource_interface_ethernet_switch_vlan.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package routeros

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

/*
{
".id": "*2",
"disabled": "false",
"invalid": "false",
"ports": "ether1",
"switch": "switch1",
"vlan-id": "0"
}
*/

// https://help.mikrotik.com/docs/display/ROS/Switch+Chip+Features#SwitchChipFeatures-VLANTable
func ResourceInterfaceEthernetSwitchVlan() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/interface/ethernet/switch/vlan"),
MetaId: PropId(Id),

KeyComment: PropCommentRw,
KeyDisabled: PropDisabledRw,
"independent_learning": {
Type: schema.TypeBool,
Optional: true,
Description: "Whether to use shared-VLAN-learning (SVL) or independent-VLAN-learning (IVL).",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
KeyInvalid: PropInvalidRo,
"ports": {
Type: schema.TypeList,
Required: true,
Description: "Interface member list for the respective VLAN.",
Elem: &schema.Schema{
Type: schema.TypeString,
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
},
"switch": {
Type: schema.TypeString,
Required: true,
Description: "Name of the switch for which the respective VLAN entry is intended for.",
},
"vlan_id": {
Type: schema.TypeInt,
Optional: true,
Description: "The VLAN ID for certain switch port configurations.",
ValidateFunc: validation.IntBetween(0, 4094),
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
}

return &schema.Resource{
CreateContext: DefaultCreate(resSchema),
ReadContext: DefaultRead(resSchema),
UpdateContext: DefaultUpdate(resSchema),
DeleteContext: DefaultSystemDelete(resSchema),

Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

Schema: resSchema,
}
}
9 changes: 9 additions & 0 deletions routeros/resource_interface_ethernet_switch_vlan_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package routeros

import (
"testing"
)

func TestAccInterfaceEthernetSwitchVlan_basic(t *testing.T) {
t.Log("Test skipped, The test is skipped, the resource is only available on real hardware.")
}

0 comments on commit 7463f0e

Please sign in to comment.