Skip to content

Commit

Permalink
feat: Add RADIUS resource
Browse files Browse the repository at this point in the history
  • Loading branch information
dokmic authored and vaerh committed Nov 15, 2023
1 parent 579f0a0 commit eb0b5c3
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/resources/routeros_radius/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 [/radius get [print show-ids]]
terraform import routeros_radius.user_manager *1
4 changes: 4 additions & 0 deletions examples/resources/routeros_radius/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "routeros_radius" "user_manager" {
address = "127.0.0.1"
service = "ppp,login"
}
3 changes: 3 additions & 0 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ func Provider() *schema.Provider {
"routeros_ppp_profile": ResourcePPPProfile(),
"routeros_ppp_secret": ResourcePPPSecret(),

// RADIUS
"routeros_radius": ResourceRadius(),

// SNMP
"routeros_snmp": ResourceSNMP(),
"routeros_snmp_community": ResourceSNMPCommunity(),
Expand Down
108 changes: 108 additions & 0 deletions routeros/resource_radius.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package routeros

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

// https://help.mikrotik.com/docs/display/ROS/RADIUS#RADIUS-RADIUSClient
func ResourceRadius() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/radius"),
MetaId: PropId(Id),

"accounting_backup": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "An option whether the configuration is for the backup RADIUS server.",
},
"accounting_port": {
Type: schema.TypeInt,
Optional: true,
Default: 1813,
Description: "RADIUS server port used for accounting.",
ValidateFunc: validation.IntBetween(0, 65535),
},
"address": {
Type: schema.TypeString,
Required: true,
Description: "IPv4 or IPv6 address of RADIUS server.",
ValidateFunc: validation.IsIPAddress,
},
"authentication_port": {
Type: schema.TypeInt,
Optional: true,
Default: 1812,
Description: "RADIUS server port used for authentication.",
ValidateFunc: validation.IntBetween(0, 65535),
},
"called_id": {
Type: schema.TypeString,
Optional: true,
Description: "RADIUS calling station identifier.",
},
"certificate": {
Type: schema.TypeString,
Optional: true,
Default: "none",
Description: "Certificate to use for communication with RADIUS Server with RadSec enabled.",
},
KeyComment: PropCommentRw,
KeyDisabled: PropDisabledRw,
"domain": {
Type: schema.TypeString,
Optional: true,
Description: "Microsoft Windows domain of client passed to RADIUS servers that require domain validation.",
},
"protocol": {
Type: schema.TypeString,
Optional: true,
Default: "udp",
Description: "An option specifies the protocol to use when communicating with the RADIUS Server.",
ValidateFunc: validation.StringInSlice([]string{"radsec", "udp"}, false),
},
"realm": {
Type: schema.TypeString,
Optional: true,
Description: "Explicitly stated realm (user domain), so the users do not have to provide proper ISP domain name in the user name.",
},
"secret": {
Type: schema.TypeString,
Optional: true,
Sensitive: true,
Description: "The shared secret to access the RADIUS server.",
},
"service": {
Type: schema.TypeString,
Optional: true,
Description: "A comma-separated list of router services that will use the RADIUS server. Possible values: `hotspot`, `login`, `ppp`, `wireless`, `dhcp`.",
},
"src_address": {
Type: schema.TypeString,
Optional: true,
Description: "Source IPv4/IPv6 address of the packets sent to the RADIUS server.",
ValidateFunc: validation.IsIPAddress,
},
"timeout": {
Type: schema.TypeString,
Optional: true,
Default: "300ms",
Description: "A timeout, after which the request should be resent.",
DiffSuppressFunc: TimeEquall,
},
}

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 eb0b5c3

Please sign in to comment.