From 18999832de2ff864008b1f84cc0801fdfc9697c5 Mon Sep 17 00:00:00 2001 From: Michael Dokolin Date: Wed, 6 Dec 2023 08:11:22 +0100 Subject: [PATCH] feat: Add system user authentication and accounting settings resource --- .../routeros_system_user_aaa/import.sh | 1 + .../routeros_system_user_aaa/resource.tf | 3 + routeros/provider.go | 1 + routeros/resource_system_user_aaa.go | 68 +++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 examples/resources/routeros_system_user_aaa/import.sh create mode 100644 examples/resources/routeros_system_user_aaa/resource.tf create mode 100644 routeros/resource_system_user_aaa.go diff --git a/examples/resources/routeros_system_user_aaa/import.sh b/examples/resources/routeros_system_user_aaa/import.sh new file mode 100644 index 00000000..14432910 --- /dev/null +++ b/examples/resources/routeros_system_user_aaa/import.sh @@ -0,0 +1 @@ +terraform import routeros_system_user_aaa.settings . diff --git a/examples/resources/routeros_system_user_aaa/resource.tf b/examples/resources/routeros_system_user_aaa/resource.tf new file mode 100644 index 00000000..45ab9cec --- /dev/null +++ b/examples/resources/routeros_system_user_aaa/resource.tf @@ -0,0 +1,3 @@ +resource "routeros_system_user_aaa" "settings" { + use_radius = true +} diff --git a/routeros/provider.go b/routeros/provider.go index 32d89035..4ed2fb0c 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_aaa": ResourceUserAaa(), "routeros_system_user_group": ResourceUserGroup(), "routeros_system_user_settings": ResourceSystemUserSettings(), diff --git a/routeros/resource_system_user_aaa.go b/routeros/resource_system_user_aaa.go new file mode 100644 index 00000000..80df0ab4 --- /dev/null +++ b/routeros/resource_system_user_aaa.go @@ -0,0 +1,68 @@ +package routeros + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +/* +{ + "accounting": "true", + "default-group": "read", + "exclude-groups": "full", + "interim-update": "0s", + "use-radius": "false" +} +*/ + +// https://help.mikrotik.com/docs/display/ROS/User#User-RemoteAAA +func ResourceUserAaa() *schema.Resource { + resSchema := map[string]*schema.Schema{ + MetaResourcePath: PropResourcePath("/user/aaa"), + MetaId: PropId(Id), + + "accounting": { + Type: schema.TypeBool, + Optional: true, + Default: true, + Description: "An option that enables accounting for users.", + }, + "default_group": { + Type: schema.TypeString, + Optional: true, + Default: "read", + Description: "The user group that is used by default for users authenticated via a RADIUS server.", + }, + "exclude_groups": { + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Description: "A set of groups that are not allowed for users authenticated by RADIUS.", + }, + "interim_update": { + Type: schema.TypeString, + Optional: true, + Default: "0s", + Description: "Interval between scheduled RADIUS Interim-Update messages.", + DiffSuppressFunc: TimeEquall, + }, + "use_radius": { + Type: schema.TypeBool, + Optional: true, + Default: false, + Description: "An option whether to use RADIUS server.", + }, + } + + return &schema.Resource{ + CreateContext: DefaultSystemCreate(resSchema), + ReadContext: DefaultSystemRead(resSchema), + UpdateContext: DefaultSystemUpdate(resSchema), + DeleteContext: DefaultSystemDelete(resSchema), + + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Schema: resSchema, + } +}