From c7cc658b69c5e75033c4eddfebc42f928bccd4e2 Mon Sep 17 00:00:00 2001 From: Michael Dokolin Date: Sat, 2 Dec 2023 08:12:23 +0100 Subject: [PATCH] feat: Add system user group resource --- .../routeros_system_user_group/import.sh | 3 + .../routeros_system_user_group/resource.tf | 4 ++ routeros/provider.go | 1 + routeros/resource_system_user_group.go | 58 +++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 examples/resources/routeros_system_user_group/import.sh create mode 100644 examples/resources/routeros_system_user_group/resource.tf create mode 100644 routeros/resource_system_user_group.go diff --git a/examples/resources/routeros_system_user_group/import.sh b/examples/resources/routeros_system_user_group/import.sh new file mode 100644 index 00000000..6dc85c1e --- /dev/null +++ b/examples/resources/routeros_system_user_group/import.sh @@ -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 diff --git a/examples/resources/routeros_system_user_group/resource.tf b/examples/resources/routeros_system_user_group/resource.tf new file mode 100644 index 00000000..4c81a652 --- /dev/null +++ b/examples/resources/routeros_system_user_group/resource.tf @@ -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"] +} diff --git a/routeros/provider.go b/routeros/provider.go index 70022bcb..1e1a6c23 100644 --- a/routeros/provider.go +++ b/routeros/provider.go @@ -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(), diff --git a/routeros/resource_system_user_group.go b/routeros/resource_system_user_group.go new file mode 100644 index 00000000..16ec6d52 --- /dev/null +++ b/routeros/resource_system_user_group.go @@ -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, + } +}