From db763696e4003399b76cb474ea32614a4e8028db Mon Sep 17 00:00:00 2001 From: Michael Dokolin Date: Tue, 7 Nov 2023 23:18:21 +0100 Subject: [PATCH] feat: Add 802.1X client resource --- .../routeros_interface_dot1x_client/import.sh | 3 + .../resource.tf | 5 ++ routeros/provider.go | 1 + routeros/resource_interface_dot1x.go | 61 +++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 examples/resources/routeros_interface_dot1x_client/import.sh create mode 100644 examples/resources/routeros_interface_dot1x_client/resource.tf create mode 100644 routeros/resource_interface_dot1x.go diff --git a/examples/resources/routeros_interface_dot1x_client/import.sh b/examples/resources/routeros_interface_dot1x_client/import.sh new file mode 100644 index 00000000..4222fe56 --- /dev/null +++ b/examples/resources/routeros_interface_dot1x_client/import.sh @@ -0,0 +1,3 @@ +#The ID can be found via API or the terminal +#The command for the terminal is -> :put [/interface/dot1x/client get [print show-ids]] +terraform import routeros_interface_dot1x_client.ether2 *1 diff --git a/examples/resources/routeros_interface_dot1x_client/resource.tf b/examples/resources/routeros_interface_dot1x_client/resource.tf new file mode 100644 index 00000000..bad3d219 --- /dev/null +++ b/examples/resources/routeros_interface_dot1x_client/resource.tf @@ -0,0 +1,5 @@ +resource "routeros_interface_dot1x_client" "ether2" { + eap_methods = "eap-peap,eap-mschapv2" + identity = "router" + interface = "ether2" +} diff --git a/routeros/provider.go b/routeros/provider.go index 984f9280..06144c51 100644 --- a/routeros/provider.go +++ b/routeros/provider.go @@ -104,6 +104,7 @@ func Provider() *schema.Provider { "routeros_interface_bridge_port": ResourceInterfaceBridgePort(), "routeros_interface_bridge_vlan": ResourceInterfaceBridgeVlan(), "routeros_interface_bridge_settings": ResourceInterfaceBridgeSettings(), + "routeros_interface_dot1x_client": ResourceInterfaceDot1xClient(), "routeros_interface_eoip": ResourceInterfaceEoip(), "routeros_interface_ethernet_switch": ResourceInterfaceEthernetSwitch(), "routeros_interface_gre": ResourceInterfaceGre(), diff --git a/routeros/resource_interface_dot1x.go b/routeros/resource_interface_dot1x.go new file mode 100644 index 00000000..a3989d57 --- /dev/null +++ b/routeros/resource_interface_dot1x.go @@ -0,0 +1,61 @@ +package routeros + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +// https://help.mikrotik.com/docs/display/ROS/Dot1X#Dot1X-Client +func ResourceInterfaceDot1xClient() *schema.Resource { + resSchema := map[string]*schema.Schema{ + MetaResourcePath: PropResourcePath("/interface/dot1x/client"), + MetaId: PropId(Id), + + "anon_identity": { + Type: schema.TypeString, + Optional: true, + Description: "Identity for outer layer EAP authentication. Used only with `eap-ttls` and `eap-peap` methods. If not set, the value from the identity parameter will be used for outer layer EAP authentication.", + }, + "certificate": { + Type: schema.TypeString, + Optional: true, + Default: "none", + Description: "Name of a certificate. Required when the `eap-tls` method is used.", + }, + KeyComment: PropCommentRw, + KeyDisabled: PropDisabledRw, + "eap_methods": { + Type: schema.TypeString, + Required: true, + Description: "A list of EAP methods used for authentication: `eap-tls`, `eap-ttls`, `eap-peap`, `eap-mschapv2`.", + }, + "identity": { + Type: schema.TypeString, + Required: true, + Description: "The supplicant identity that is used for EAP authentication.", + }, + KeyInterface: PropInterfaceRw, + "password": { + Type: schema.TypeString, + Optional: true, + Sensitive: true, + Description: "Cleartext password for the supplicant.", + }, + "status": { + Type: schema.TypeString, + Computed: true, + }, + } + + return &schema.Resource{ + CreateContext: DefaultCreate(resSchema), + ReadContext: DefaultRead(resSchema), + UpdateContext: DefaultUpdate(resSchema), + DeleteContext: DefaultDelete(resSchema), + + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Schema: resSchema, + } +}