Skip to content

Commit

Permalink
feat: Add tool/mac-server support
Browse files Browse the repository at this point in the history
Fixes #387
  • Loading branch information
vaerh committed Mar 27, 2024
1 parent bcffe58 commit 3f8a2b5
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 0 deletions.
4 changes: 4 additions & 0 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ func Provider() *schema.Provider {
"routeros_wireguard_keys": ResourceWireguardKeys(),
"routeros_move_items": ResourceMoveItems(),

// Tools
"routeros_tool_mac_server": ResourceToolMacServer(),
"routeros_tool_mac_server_winbox": ResourceToolMacServerWinBox(),

// User Manager
"routeros_user_manager_advanced": ResourceUserManagerAdvanced(),
"routeros_user_manager_attribute": ResourceUserManagerAttribute(),
Expand Down
65 changes: 65 additions & 0 deletions routeros/resource_system_tool_mac_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package routeros

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

/*
{
"allowed-interface-list": "LAN"
}
*/

// https://help.mikrotik.com/docs/display/ROS/MAC+server
func ResourceToolMacServer() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/tool/mac-server"),
MetaId: PropId(Id),

"allowed_interface_list": {
Type: schema.TypeString,
Required: true,
Description: "List of interfaces for MAC Telnet access.",
},
}

return &schema.Resource{
CreateContext: DefaultSystemCreate(resSchema),
ReadContext: DefaultSystemRead(resSchema),
UpdateContext: DefaultSystemUpdate(resSchema),
DeleteContext: DefaultSystemDelete(resSchema),

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

Schema: resSchema,
}
}

// https://help.mikrotik.com/docs/display/ROS/MAC+server
func ResourceToolMacServerWinBox() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/tool/mac-server/mac-winbox"),
MetaId: PropId(Id),

"allowed_interface_list": {
Type: schema.TypeString,
Required: true,
Description: "List of interfaces for MAC WinBox access.",
},
}

return &schema.Resource{
CreateContext: DefaultSystemCreate(resSchema),
ReadContext: DefaultSystemRead(resSchema),
UpdateContext: DefaultSystemUpdate(resSchema),
DeleteContext: DefaultSystemDelete(resSchema),

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

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

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

const testToolsMacServer = "routeros_tool_mac_server.test"

func TestAccToolsMacServerTest_basic(t *testing.T) {
for _, name := range testNames {
t.Run(name, func(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testSetTransportEnv(t, name)
},
ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccToolsMacServerConfig("none"),
Check: resource.ComposeTestCheckFunc(
testResourcePrimaryInstanceId(testToolsMacServer),
resource.TestCheckResourceAttr(testToolsMacServer, "allowed_interface_list", "none"),
),
},
{
Config: testAccToolsMacServerConfig("LAN"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testToolsMacServer, "allowed_interface_list", "LAN"),
),
},
},
})
})
}
}

const testToolsMacServerWinBox = "routeros_tool_mac_server_winbox.test"

func TestAccToolsMacServerWinBoxTest_basic(t *testing.T) {
for _, name := range testNames {
t.Run(name, func(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testSetTransportEnv(t, name)
},
ProviderFactories: testAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccToolsMacServerWinBoxConfig("none"),
Check: resource.ComposeTestCheckFunc(
testResourcePrimaryInstanceId(testToolsMacServerWinBox),
resource.TestCheckResourceAttr(testToolsMacServerWinBox, "allowed_interface_list", "none"),
),
},
{
Config: testAccToolsMacServerWinBoxConfig("LAN"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(testToolsMacServerWinBox, "allowed_interface_list", "LAN"),
),
},
},
})
})
}
}

func testAccToolsMacServerConfig(acl string) string {
return fmt.Sprintf(`%v
resource "routeros_tool_mac_server" "test" {
allowed_interface_list = "%v"
}
`, providerConfig, acl)
}

func testAccToolsMacServerWinBoxConfig(acl string) string {
return fmt.Sprintf(`%v
resource "routeros_tool_mac_server_winbox" "test" {
allowed_interface_list = "%v"
}
`, providerConfig, acl)
}

0 comments on commit 3f8a2b5

Please sign in to comment.