From 95006359d071dc3c4ef2c3c19bf5847ab6f3dbbe Mon Sep 17 00:00:00 2001 From: Michael Dokolin Date: Thu, 30 Nov 2023 18:01:15 +0100 Subject: [PATCH] feat: Add user manager user profile resource --- .../import.sh | 3 ++ .../resource.tf | 12 +++++ routeros/provider.go | 1 + .../resource_user_manager_user_profile.go | 48 +++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 examples/resources/routeros_user_manager_user_profile/import.sh create mode 100644 examples/resources/routeros_user_manager_user_profile/resource.tf create mode 100644 routeros/resource_user_manager_user_profile.go diff --git a/examples/resources/routeros_user_manager_user_profile/import.sh b/examples/resources/routeros_user_manager_user_profile/import.sh new file mode 100644 index 00000000..e5049760 --- /dev/null +++ b/examples/resources/routeros_user_manager_user_profile/import.sh @@ -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' diff --git a/examples/resources/routeros_user_manager_user_profile/resource.tf b/examples/resources/routeros_user_manager_user_profile/resource.tf new file mode 100644 index 00000000..9b80e38e --- /dev/null +++ b/examples/resources/routeros_user_manager_user_profile/resource.tf @@ -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 +} diff --git a/routeros/provider.go b/routeros/provider.go index 95aea6b7..ac16b5f6 100644 --- a/routeros/provider.go +++ b/routeros/provider.go @@ -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(), diff --git a/routeros/resource_user_manager_user_profile.go b/routeros/resource_user_manager_user_profile.go new file mode 100644 index 00000000..8c61d55e --- /dev/null +++ b/routeros/resource_user_manager_user_profile.go @@ -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, + } +}