Skip to content

Commit

Permalink
feat: Add 802.1X server resource
Browse files Browse the repository at this point in the history
  • Loading branch information
dokmic authored and vaerh committed Nov 10, 2023
1 parent db76369 commit 05894af
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/resources/routeros_interface_dot1x_server/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 [/interface/dot1x/server get [print show-ids]]
terraform import routeros_interface_dot1x_server.ether2 *1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "routeros_interface_dot1x_server" "ether2" {
auth_types = "mac-auth"
interface = "ether2"
}
1 change: 1 addition & 0 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func Provider() *schema.Provider {
"routeros_interface_bridge_vlan": ResourceInterfaceBridgeVlan(),
"routeros_interface_bridge_settings": ResourceInterfaceBridgeSettings(),
"routeros_interface_dot1x_client": ResourceInterfaceDot1xClient(),
"routeros_interface_dot1x_server": ResourceInterfaceDot1xServer(),
"routeros_interface_eoip": ResourceInterfaceEoip(),
"routeros_interface_ethernet_switch": ResourceInterfaceEthernetSwitch(),
"routeros_interface_gre": ResourceInterfaceGre(),
Expand Down
98 changes: 98 additions & 0 deletions routeros/resource_interface_dot1x.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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/Dot1X#Dot1X-Client
Expand Down Expand Up @@ -59,3 +60,100 @@ func ResourceInterfaceDot1xClient() *schema.Resource {
Schema: resSchema,
}
}

// https://help.mikrotik.com/docs/display/ROS/Dot1X#Dot1X-Server
func ResourceInterfaceDot1xServer() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/interface/dot1x/server"),
MetaId: PropId(Id),

"accounting": {
Type: schema.TypeBool,
Optional: true,
Default: true,
Description: "Whether to send RADIUS accounting requests to the authentication server.",
},
"auth_timeout": {
Type: schema.TypeString,
Optional: true,
Default: "1m",
Description: "Total time available for EAP authentication.",
DiffSuppressFunc: TimeEquall,
},
"auth_types": {
Type: schema.TypeString,
Optional: true,
Default: "dot1x",
Description: "Used authentication type on a server interface. Comma-separated list of `dot1x` and `mac-auth`.",
},
KeyComment: PropCommentRw,
KeyDisabled: PropDisabledRw,
"guest_vlan_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Assigned VLAN when end devices do not support dot1x authentication and no mac-auth fallback is configured.",
ValidateFunc: validation.IntBetween(1, 4094),
},
KeyInterface: PropInterfaceRw,
"interim_update": {
Type: schema.TypeString,
Optional: true,
Default: "0s",
Description: "Interval between scheduled RADIUS Interim-Update messages.",
DiffSuppressFunc: TimeEquall,
},
"mac_auth_mode": {
Type: schema.TypeString,
Optional: true,
Default: "mac-as-username",
Description: "An option that allows to control User-Name and User-Password RADIUS attributes when using MAC authentication.",
ValidateFunc: validation.StringInSlice([]string{"mac-as-username", "mac-as-username-and-password"}, false),
},
"radius_mac_format": {
Type: schema.TypeString,
Optional: true,
Default: "XX:XX:XX:XX:XX:XX",
Description: "An option that controls how the MAC address of the client is encoded in the User-Name and User-Password attributes when using MAC authentication.",
ValidateFunc: validation.StringInSlice([]string{"XX-XX-XX-XX-XX-XX", "XX:XX:XX:XX:XX:XX", "XXXXXXXXXXXX",
"xx-xx-xx-xx-xx-xx", "xx:xx:xx:xx:xx:xx", "xxxxxxxxxxxx"}, false),
},
"reauth_timeout": {
Type: schema.TypeString,
Optional: true,
Description: "An option that enables server port re-authentication.",
DiffSuppressFunc: TimeEquall,
},
"reject_vlan_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Assigned VLAN when authentication failed, and a RADIUS server responded with an Access-Reject message. ",
ValidateFunc: validation.IntBetween(1, 4094),
},
"retrans_timeout": {
Type: schema.TypeString,
Optional: true,
Default: "30s",
Description: "The time interval between message re-transmissions if no response is received from the supplicant.",
DiffSuppressFunc: TimeEquall,
},
"server_fail_vlan_id": {
Type: schema.TypeInt,
Optional: true,
Description: "Assigned VLAN when RADIUS server is not responding and request timed out.",
ValidateFunc: validation.IntBetween(1, 4094),
},
}

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 05894af

Please sign in to comment.