Skip to content

Commit

Permalink
feat: Add user manager user profile 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 727cd9b commit 9500635
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
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-profile get [print show-ids]]
terraform import routeros_user_manager_user_profile.test '*1'
12 changes: 12 additions & 0 deletions examples/resources/routeros_user_manager_user_profile/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
resource "routeros_user_manager_profile" "test" {
name = "test"
}

resource "routeros_user_manager_user" "test" {
name = "test"
}

resource "routeros_user_manager_user_profile" "test" {
profile = routeros_user_manager_profile.test.name
user = routeros_user_manager_user.test.name
}
1 change: 1 addition & 0 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func Provider() *schema.Provider {
"routeros_user_manager_settings": ResourceUserManagerSettings(),
"routeros_user_manager_user": ResourceUserManagerUser(),
"routeros_user_manager_user_group": ResourceUserManagerUserGroup(),
"routeros_user_manager_user_profile": ResourceUserManagerUserProfile(),
},
DataSourcesMap: map[string]*schema.Resource{
"routeros_firewall": DatasourceFirewall(),
Expand Down
48 changes: 48 additions & 0 deletions routeros/resource_user_manager_user_profile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package routeros

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

/*
{
".id": "*1",
"end-time": "unlimited",
"profile": "test",
"state": "running",
"user": "test"
}
*/

// https://help.mikrotik.com/docs/display/ROS/User+Manager#UserManager-UserProfiles
func ResourceUserManagerUserProfile() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/user-manager/user-profile"),
MetaId: PropId(Id),
MetaSkipFields: PropSkipFields(`"end_time","state"`),

"profile": {
Type: schema.TypeString,
Required: true,
Description: "Name of the profile to assign to the user.",
},
"user": {
Type: schema.TypeString,
Required: true,
Description: "Name of the user to use the specified profile.",
},
}

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 9500635

Please sign in to comment.