Skip to content

Commit

Permalink
feat: Add user manager router resource
Browse files Browse the repository at this point in the history
  • Loading branch information
dokmic authored and vaerh committed Dec 2, 2023
1 parent 733932c commit 162e01e
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/resources/routeros_user_manager_router/import.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#The ID can be found via API or the terminal
#The command for the terminal is -> :put [/user-manager/router get [print show-ids]]
terraform import routeros_user_manager_router.test '*1'
5 changes: 5 additions & 0 deletions examples/resources/routeros_user_manager_router/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "routeros_user_manager_router" "test" {
address = "127.0.0.1"
name = "test"
shared_secret = "password"
}
1 change: 1 addition & 0 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ func Provider() *schema.Provider {
"routeros_user_manager_limitation": ResourceUserManagerLimitation(),
"routeros_user_manager_profile": ResourceUserManagerProfile(),
"routeros_user_manager_profile_limitation": ResourceUserManagerProfileLimitation(),
"routeros_user_manager_router": ResourceUserManagerRouter(),
"routeros_user_manager_settings": ResourceUserManagerSettings(),
},
DataSourcesMap: map[string]*schema.Resource{
Expand Down
60 changes: 60 additions & 0 deletions routeros/resource_user_manager_router.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package routeros

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

/*
{
".id": "*1",
"address": "127.0.0.1",
"coa-port": "3799",
"disabled": "false",
"name": "test",
"shared-secret": "password"
}
*/

// https://help.mikrotik.com/docs/display/ROS/User+Manager#UserManager-Routers
func ResourceUserManagerRouter() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/user-manager/router"),
MetaId: PropId(Id),

"address": {
Type: schema.TypeString,
Required: true,
Description: "IP address of the RADIUS client.",
ValidateFunc: validation.IsIPAddress,
},
"coa_port": {
Type: schema.TypeInt,
Optional: true,
Default: 3799,
Description: "Port number of CoA (Change of Authorization) communication.",
ValidateFunc: validation.IntBetween(0, 65535),
},
KeyDisabled: PropDisabledRw,
KeyName: PropName("Unique name of the RADIUS client."),
"shared_secret": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
Description: "The shared secret to secure communication.",
},
}

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 162e01e

Please sign in to comment.