-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add user manager user resource
- Loading branch information
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |