From f889b7bd95bf4f559888edcfb32640b8d4fd731a Mon Sep 17 00:00:00 2001 From: Michael Dokolin Date: Sun, 3 Dec 2023 07:48:55 +0100 Subject: [PATCH] feat: Add system user settings resource --- .../routeros_system_user_settings/import.sh | 1 + .../routeros_system_user_settings/resource.tf | 4 ++ routeros/provider.go | 17 ++++--- routeros/resource_system_user_settings.go | 49 +++++++++++++++++++ 4 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 examples/resources/routeros_system_user_settings/import.sh create mode 100644 examples/resources/routeros_system_user_settings/resource.tf create mode 100644 routeros/resource_system_user_settings.go diff --git a/examples/resources/routeros_system_user_settings/import.sh b/examples/resources/routeros_system_user_settings/import.sh new file mode 100644 index 00000000..555f5564 --- /dev/null +++ b/examples/resources/routeros_system_user_settings/import.sh @@ -0,0 +1 @@ +terraform import routeros_system_user_settings.settings . diff --git a/examples/resources/routeros_system_user_settings/resource.tf b/examples/resources/routeros_system_user_settings/resource.tf new file mode 100644 index 00000000..e01abfd8 --- /dev/null +++ b/examples/resources/routeros_system_user_settings/resource.tf @@ -0,0 +1,4 @@ +resource "routeros_system_user_settings" "settings" { + minimum_categories = 2 + minimum_password_length = 8 +} diff --git a/routeros/provider.go b/routeros/provider.go index 1e1a6c23..32d89035 100644 --- a/routeros/provider.go +++ b/routeros/provider.go @@ -133,14 +133,15 @@ func Provider() *schema.Provider { "routeros_wireguard_peer": ResourceInterfaceWireguardPeer(), // System Objects - "routeros_ip_cloud": ResourceIpCloud(), - "routeros_system_certificate": ResourceSystemCertificate(), - "routeros_system_identity": ResourceSystemIdentity(), - "routeros_system_logging": ResourceSystemLogging(), - "routeros_system_ntp_server": ResourceSystemNtpServer(), - "routeros_system_scheduler": ResourceSystemScheduler(), - "routeros_system_user": ResourceUser(), - "routeros_system_user_group": ResourceUserGroup(), + "routeros_ip_cloud": ResourceIpCloud(), + "routeros_system_certificate": ResourceSystemCertificate(), + "routeros_system_identity": ResourceSystemIdentity(), + "routeros_system_logging": ResourceSystemLogging(), + "routeros_system_ntp_server": ResourceSystemNtpServer(), + "routeros_system_scheduler": ResourceSystemScheduler(), + "routeros_system_user": ResourceUser(), + "routeros_system_user_group": ResourceUserGroup(), + "routeros_system_user_settings": ResourceSystemUserSettings(), // Aliases for system objects to retain compatibility between original and fork "routeros_identity": ResourceSystemIdentity(), diff --git a/routeros/resource_system_user_settings.go b/routeros/resource_system_user_settings.go new file mode 100644 index 00000000..7eb9241a --- /dev/null +++ b/routeros/resource_system_user_settings.go @@ -0,0 +1,49 @@ +package routeros + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +/* +{ + "minimum-categories": "0", + "minimum-password-length": "0" +} +*/ + +// https://help.mikrotik.com/docs/display/ROS/User#User-UserSettings +func ResourceSystemUserSettings() *schema.Resource { + resSchema := map[string]*schema.Schema{ + MetaResourcePath: PropResourcePath("/user/settings"), + MetaId: PropId(Id), + + "minimum_categories": { + Type: schema.TypeInt, + Optional: true, + Default: 0, + Description: "An option specifies the complexity requirements of the password, with categories being uppercase, lowercase, digit, and symbol.", + ValidateFunc: validation.IntBetween(0, 4), + }, + "minimum_password_length": { + Type: schema.TypeInt, + Optional: true, + Default: 0, + Description: "An option specifies the minimum length of the password.", + ValidateFunc: validation.IntAtLeast(0), + }, + } + + return &schema.Resource{ + CreateContext: DefaultSystemCreate(resSchema), + ReadContext: DefaultSystemRead(resSchema), + UpdateContext: DefaultSystemUpdate(resSchema), + DeleteContext: DefaultSystemDelete(resSchema), + + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Schema: resSchema, + } +}