Skip to content

Commit

Permalink
feat: Add user manager user 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 fff1568 commit 727cd9b
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/resources/routeros_user_manager_user/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/user get [print show-ids]]
terraform import routeros_user_manager_user.test '*1'
25 changes: 25 additions & 0 deletions examples/resources/routeros_user_manager_user/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
resource "routeros_user_manager_attribute" "mikrotik_wireless_comment" {
name = "Mikrotik-Wireless-Comment"
type_id = 21
value_type = "string"
}

resource "routeros_user_manager_attribute" "mikrotik_wireless_vlanid" {
name = "Mikrotik-Wireless-VLANID"
type_id = 26
value_type = "uint32"
}

resource "routeros_user_manager_user_group" "test" {
name = "test"
}

resource "routeros_user_manager_user" "test" {
attributes = [
"${routeros_user_manager_attribute.mikrotik_wireless_comment.name}:Test Group",
"${routeros_user_manager_attribute.mikrotik_wireless_vlanid.name}:100",
]
group = routeros_user_manager_user_group.test.name
name = "test"
password = "password"
}
1 change: 1 addition & 0 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func Provider() *schema.Provider {
"routeros_user_manager_profile_limitation": ResourceUserManagerProfileLimitation(),
"routeros_user_manager_router": ResourceUserManagerRouter(),
"routeros_user_manager_settings": ResourceUserManagerSettings(),
"routeros_user_manager_user": ResourceUserManagerUser(),
"routeros_user_manager_user_group": ResourceUserManagerUserGroup(),
},
DataSourcesMap: map[string]*schema.Resource{
Expand Down
78 changes: 78 additions & 0 deletions routeros/resource_user_manager_user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package routeros

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

/*
{
".id": "*1",
"attributes": "",
"caller-id": "bind",
"comment": "test",
"disabled": "false",
"group": "test",
"name": "test",
"otp-secret": "",
"password": "password",
"shared-users": "1"
}
*/

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

"attributes": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "A custom set of colon-separated attributes with their values will be added to `Access-Accept` messages for users in this group.",
},
"caller_id": {
Type: schema.TypeString,
Optional: true,
Description: "Allow user's authentication with a specific Calling-Station-Id value.",
},
KeyComment: PropCommentRw,
KeyDisabled: PropDisabledRw,
"group": {
Type: schema.TypeString,
Optional: true,
Description: "Name of the group the user is associated with.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
KeyName: PropName("Username for session authentication."),
"otp_secret": {
Type: schema.TypeString,
Optional: true,
Description: "A token of a one-time code that will be attached to the password.",
},
"password": {
Type: schema.TypeString,
Optional: true,
Description: "The password of the user for session authentication.",
},
"shared_users": {
Type: schema.TypeInt,
Optional: true,
Default: 1,
Description: "The total amount of sessions the user can simultaneously establish.",
},
}

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 727cd9b

Please sign in to comment.