Skip to content

Commit

Permalink
feat: Add user manager profile limitation 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 d95bed1 commit 733932c
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 6 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/profile-limitation get [print show-ids]]
terraform import routeros_user_manager_profile_limitation.weekend_night '*1'
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
resource "routeros_user_manager_limitation" "test" {
name = "test"
download_limit = 1024
upload_limit = 1024
uptime_limit = "10d"
}

resource "routeros_user_manager_profile" "test" {
name = "test"
name_for_users = "Test"
price = 0.02
}

resource "routeros_user_manager_profile_limitation" "weekend_night" {
limitation = routeros_user_manager_limitation.test.name
profile = routeros_user_manager_profile.test.name
from_time = "0s"
till_time = "6h"
weekdays = [
"sunday",
"saturday",
]
}
13 changes: 7 additions & 6 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,13 @@ func Provider() *schema.Provider {
"routeros_wireguard_keys": ResourceWireguardKeys(),

// User Manager
"routeros_user_manager_advanced": ResourceUserManagerAdvanced(),
"routeros_user_manager_attribute": ResourceUserManagerAttribute(),
"routeros_user_manager_database": ResourceUserManagerDatabase(),
"routeros_user_manager_limitation": ResourceUserManagerLimitation(),
"routeros_user_manager_profile": ResourceUserManagerProfile(),
"routeros_user_manager_settings": ResourceUserManagerSettings(),
"routeros_user_manager_advanced": ResourceUserManagerAdvanced(),
"routeros_user_manager_attribute": ResourceUserManagerAttribute(),
"routeros_user_manager_database": ResourceUserManagerDatabase(),
"routeros_user_manager_limitation": ResourceUserManagerLimitation(),
"routeros_user_manager_profile": ResourceUserManagerProfile(),
"routeros_user_manager_profile_limitation": ResourceUserManagerProfileLimitation(),
"routeros_user_manager_settings": ResourceUserManagerSettings(),
},
DataSourcesMap: map[string]*schema.Resource{
"routeros_firewall": DatasourceFirewall(),
Expand Down
73 changes: 73 additions & 0 deletions routeros/resource_user_manager_profile_limitation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package routeros

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

/*
{
".id": "*1",
"from-time": "0s",
"limitation": "test",
"profile": "test",
"till-time": "23h59m59s",
"weekdays": "sunday,monday,tuesday,wednesday,thursday,friday,saturday"
}
*/

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

"from_time": {
Type: schema.TypeString,
Optional: true,
Default: "0s",
Description: "Time of the day when the limitation should take place.",
DiffSuppressFunc: TimeEquall,
},
"limitation": {
Type: schema.TypeString,
Required: true,
Description: "The limitation name.",
},
"profile": {
Type: schema.TypeString,
Required: true,
Description: "The profile name.",
},
"till_time": {
Type: schema.TypeString,
Optional: true,
Default: "23h59m59s",
Description: "Time of the day when the limitation should end.",
DiffSuppressFunc: TimeEquall,
},
"weekdays": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{"sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"}, false),
},
Description: "Days of the week when the limitation is active.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
}

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 733932c

Please sign in to comment.