Skip to content

Commit

Permalink
feat: Add system user group resource
Browse files Browse the repository at this point in the history
  • Loading branch information
dokmic authored and vaerh committed Jan 5, 2024
1 parent adfbfaf commit c7cc658
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/resources/routeros_system_user_group/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/group get [print show-ids]]
terraform import routeros_system_user_group.terraform *1
4 changes: 4 additions & 0 deletions examples/resources/routeros_system_user_group/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "routeros_system_user_group" "terraform" {
name = "terraform"
policy = ["api", "!ftp", "!local", "password", "policy", "read", "!reboot", "!rest-api", "!romon", "sensitive", "!sniff", "!ssh", "!telnet", "!test", "!web", "!winbox", "write"]
}
1 change: 1 addition & 0 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func Provider() *schema.Provider {
"routeros_system_ntp_server": ResourceSystemNtpServer(),
"routeros_system_scheduler": ResourceSystemScheduler(),
"routeros_system_user": ResourceUser(),
"routeros_system_user_group": ResourceUserGroup(),

// Aliases for system objects to retain compatibility between original and fork
"routeros_identity": ResourceSystemIdentity(),
Expand Down
58 changes: 58 additions & 0 deletions routeros/resource_system_user_group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package routeros

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

/*
{
".id": "*1",
"name": "read",
"policy": "local,telnet,ssh,reboot,read,test,winbox,password,web,sniff,sensitive,api,romon,rest-api,!ftp,!write,!policy",
"skin": "default"
}
*/

// https://help.mikrotik.com/docs/display/ROS/User#User-UserGroups
func ResourceUserGroup() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/user/group"),
MetaId: PropId(Id),

KeyComment: PropCommentRw,
KeyName: PropName("The name of the user group"),
"policy": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.StringInSlice([]string{
"api", "dude", "ftp", "local", "password", "policy", "read", "reboot", "rest-api", "romon", "sensitive", "sniff", "ssh", "telnet", "test", "tikapp", "web", "winbox", "write",
"!api", "!dude", "!ftp", "!local", "!password", "!policy", "!read", "!reboot", "!rest-api", "!romon", "!sensitive", "!sniff", "!ssh", "!telnet", "!test", "!tikapp", "!web", "!winbox", "!write",
}, false),
},
Description: "A set of allowed policies.",
DiffSuppressFunc: AlwaysPresentNotUserProvided,
},
"skin": {
Type: schema.TypeString,
Optional: true,
Default: "default",
Description: "The name of the skin that will be used for WebFig.",
},
}

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 c7cc658

Please sign in to comment.