Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vaerh/issue325 #336

Merged
merged 7 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/ethernet/switch/host get [print show-ids]]
terraform import routeros_interface_ethernet_switch_host.test *0
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "routeros_interface_ethernet_switch_host" "test" {
switch = "switch1"
mac_address = "00:00:00:00:00:00"
ports = ["ether1"]
mirror = true
}
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/ethernet/switch/port get [print show-ids]]
terraform import routeros_interface_ethernet_switch_port.test *1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "routeros_interface_ethernet_switch_port" "test" {
name = "ether1"
vlan_mode = "check"
}
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/ethernet/switch/port-isolation get [print show-ids]]
terraform import routeros_interface_ethernet_switch_port_isolation.test *1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "routeros_interface_ethernet_switch_port_isolation" "test" {
name = "ether1"
forwarding_override = "ether1"
}
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/ethernet/switch/rule get [print show-ids]]
terraform import routeros_interface_ethernet_switch_rule.test *0
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resource "routeros_interface_ethernet_switch_rule" "test" {
switch = "switch1"
ports = ["ether1"]
copy_to_cpu = true
}
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/ethernet/switch/vlan get [print show-ids]]
terraform import routeros_interface_ethernet_switch_vlan.test *0
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
resource "routeros_interface_ethernet_switch_vlan" "test" {
switch = "switch1"
ports = ["ether1"]
vlan_id = 10
independent_learning = true
}
90 changes: 55 additions & 35 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ func Provider() *schema.Provider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"hosturl": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{"ROS_HOSTURL", "MIKROTIK_HOST"}, nil),
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.MultiEnvDefaultFunc(
[]string{"ROS_HOSTURL", "MIKROTIK_HOST"},
nil,
),
Description: `URL of the MikroTik router, default is TLS connection to REST.
* API: api[s]://host[:port]
* api://router.local
Expand All @@ -32,32 +35,44 @@ func Provider() *schema.Provider {
`,
},
"username": {
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{"ROS_USERNAME", "MIKROTIK_USER"}, nil),
Type: schema.TypeString,
Required: true,
DefaultFunc: schema.MultiEnvDefaultFunc(
[]string{"ROS_USERNAME", "MIKROTIK_USER"},
nil,
),
Description: `Username for the MikroTik WEB/Winbox.


export ROS_USERNAME=admin or export MIKROTIK_USER=admin
`,
},
"password": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{"ROS_PASSWORD", "MIKROTIK_PASSWORD"}, nil),
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.MultiEnvDefaultFunc(
[]string{"ROS_PASSWORD", "MIKROTIK_PASSWORD"},
nil,
),
Description: "Password for the MikroTik user.",
Sensitive: true,
},
"ca_certificate": {
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{"ROS_CA_CERTIFICATE", "MIKROTIK_CA_CERTIFICATE"}, nil),
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.MultiEnvDefaultFunc(
[]string{"ROS_CA_CERTIFICATE", "MIKROTIK_CA_CERTIFICATE"},
nil,
),
Description: "Path to MikroTik's certificate authority file.",
},
"insecure": {
Type: schema.TypeBool,
Optional: true,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{"ROS_INSECURE", "MIKROTIK_INSECURE"}, false),
Type: schema.TypeBool,
Optional: true,
DefaultFunc: schema.MultiEnvDefaultFunc(
[]string{"ROS_INSECURE", "MIKROTIK_INSECURE"},
false,
),
Description: "Whether to verify the SSL certificate or not.",
},
},
Expand Down Expand Up @@ -100,26 +115,31 @@ func Provider() *schema.Provider {
"routeros_dns_record": ResourceDnsRecord(),

// Interface Objects
"routeros_interface_bridge": ResourceInterfaceBridge(),
"routeros_interface_bridge_port": ResourceInterfaceBridgePort(),
"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(),
"routeros_interface_vlan": ResourceInterfaceVlan(),
"routeros_interface_vrrp": ResourceInterfaceVrrp(),
"routeros_interface_wireguard": ResourceInterfaceWireguard(),
"routeros_interface_wireguard_peer": ResourceInterfaceWireguardPeer(),
"routeros_interface_list": ResourceInterfaceList(),
"routeros_interface_list_member": ResourceInterfaceListMember(),
"routeros_interface_ovpn_server": ResourceInterfaceOpenVPNServer(),
"routeros_interface_veth": ResourceInterfaceVeth(),
"routeros_interface_bonding": ResourceInterfaceBonding(),
"routeros_interface_pppoe_client": ResourceInterfacePPPoEClient(),
"routeros_interface_ethernet": ResourceInterfaceEthernet(),
"routeros_interface_bridge": ResourceInterfaceBridge(),
"routeros_interface_bridge_port": ResourceInterfaceBridgePort(),
"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_ethernet_switch_host": ResourceInterfaceEthernetSwitchHost(),
"routeros_interface_ethernet_switch_port": ResourceInterfaceEthernetSwitchPort(),
"routeros_interface_ethernet_switch_port_isolation": ResourceInterfaceEthernetSwitchPortIsolation(),
"routeros_interface_ethernet_switch_vlan": ResourceInterfaceEthernetSwitchVlan(),
"routeros_interface_ethernet_switch_rule": ResourceInterfaceEthernetSwitchRule(),
"routeros_interface_gre": ResourceInterfaceGre(),
"routeros_interface_vlan": ResourceInterfaceVlan(),
"routeros_interface_vrrp": ResourceInterfaceVrrp(),
"routeros_interface_wireguard": ResourceInterfaceWireguard(),
"routeros_interface_wireguard_peer": ResourceInterfaceWireguardPeer(),
"routeros_interface_list": ResourceInterfaceList(),
"routeros_interface_list_member": ResourceInterfaceListMember(),
"routeros_interface_ovpn_server": ResourceInterfaceOpenVPNServer(),
"routeros_interface_veth": ResourceInterfaceVeth(),
"routeros_interface_bonding": ResourceInterfaceBonding(),
"routeros_interface_pppoe_client": ResourceInterfacePPPoEClient(),
"routeros_interface_ethernet": ResourceInterfaceEthernet(),

// Aliases for interface objects to retain compatibility between original and fork
"routeros_bridge": ResourceInterfaceBridge(),
Expand Down
21 changes: 21 additions & 0 deletions routeros/provider_schema_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,27 @@ func PropName(description string) *schema.Schema {
}
}

// PropMacAddress
func PropMacAddressRw(description string, required bool) *schema.Schema {
mac := &schema.Schema{
Type: schema.TypeString,
Description: description,
ValidateFunc: validation.IsMACAddress,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if old != "" && d.GetRawConfig().GetAttr(k).IsNull() {
return true
}
return strings.EqualFold(old, new)
},
}
if required {
mac.Required = true
} else {
mac.Optional = true
}
return mac
}

// Schema properties.
var (
PropActualMtuRo = &schema.Schema{
Expand Down
32 changes: 16 additions & 16 deletions routeros/resource_capsman_access_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ func ResourceCapsManAccessList() *schema.Resource {
MetaResourcePath: PropResourcePath("/caps-man/access-list"),
MetaId: PropId(Id),

KeyComment: PropCommentRw,
KeyComment: PropCommentRw,
KeyDisabled: PropDisabledRw,
"action": {
Type: schema.TypeString,
Optional: true,
Description: "An action to take when a client matches.",
Type: schema.TypeString,
Optional: true,
Description: "An action to take when a client matches.",
ValidateFunc: validation.StringInSlice([]string{"accept", "reject", "query-radius"}, false),
},
"allow_signal_out_of_range": {
Type: schema.TypeString,
Optional: true,
Default: "10s",
Description: "An option that permits the client's signal to be out of the range always or for some time interval.",
Type: schema.TypeString,
Optional: true,
Default: "10s",
Description: "An option that permits the client's signal to be out of the range always or for some time interval.",
DiffSuppressFunc: TimeEquall,
},
"ap_tx_limit": {
Expand Down Expand Up @@ -70,8 +70,8 @@ func ResourceCapsManAccessList() *schema.Resource {
Description: "MAC address mask to apply when comparing clients' addresses.",
},
"interface": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
Description: "Interface name to compare with an interface to which the client actually connects to.",
},
KeyPlaceBefore: PropPlaceBefore,
Expand All @@ -92,14 +92,14 @@ func ResourceCapsManAccessList() *schema.Resource {
Description: "The range in which the client signal must fall.",
},
"ssid_regexp": {
Type: schema.TypeString,
Optional: true,
Type: schema.TypeString,
Optional: true,
Description: "The regular expression to compare the actual SSID the client connects to.",
},
"time": {
Type: schema.TypeString,
Optional: true,
Default: "0s-1d,sun,mon,tue,wed,thu,fri,sat",
Default: "0s-1d,sun,mon,tue,wed,thu,fri,sat",
Description: "Time of the day and days of the week when the rule is applicable.",
},
"vlan_id": {
Expand All @@ -109,9 +109,9 @@ func ResourceCapsManAccessList() *schema.Resource {
ValidateFunc: validation.IntBetween(1, 4094),
},
"vlan_mode": {
Type: schema.TypeString,
Optional: true,
Description: "VLAN tagging mode specifies if traffic coming from a client should get tagged and untagged when it goes back to the client.",
Type: schema.TypeString,
Optional: true,
Description: "VLAN tagging mode specifies if traffic coming from a client should get tagged and untagged when it goes back to the client.",
ValidateFunc: validation.StringInSlice([]string{"no-tag", "use-service-tag", "use-tag"}, false),
},
}
Expand Down
2 changes: 1 addition & 1 deletion routeros/resource_interface_bridge_mlag _test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ import (

func TestAccInterfaceBridgeMlagTest_basic(t *testing.T) {
t.Log("Test skipped, The test is skipped, the resource is only available on real hardware.")
}
}
54 changes: 27 additions & 27 deletions routeros/resource_interface_dot1x.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func ResourceInterfaceDot1xClient() *schema.Resource {

return &schema.Resource{
CreateContext: DefaultCreate(resSchema),
ReadContext: DefaultRead(resSchema),
ReadContext: DefaultRead(resSchema),
UpdateContext: DefaultUpdate(resSchema),
DeleteContext: DefaultDelete(resSchema),

Expand All @@ -74,10 +74,10 @@ func ResourceInterfaceDot1xServer() *schema.Resource {
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.",
Type: schema.TypeString,
Optional: true,
Default: "1m",
Description: "Total time available for EAP authentication.",
DiffSuppressFunc: TimeEquall,
},
"auth_types": {
Expand All @@ -96,17 +96,17 @@ func ResourceInterfaceDot1xServer() *schema.Resource {
},
KeyInterface: PropInterfaceRw,
"interim_update": {
Type: schema.TypeString,
Optional: true,
Default: "0s",
Description: "Interval between scheduled RADIUS Interim-Update messages.",
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.",
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": {
Expand All @@ -118,35 +118,35 @@ func ResourceInterfaceDot1xServer() *schema.Resource {
"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.",
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. ",
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.",
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.",
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),
ReadContext: DefaultRead(resSchema),
UpdateContext: DefaultUpdate(resSchema),
DeleteContext: DefaultDelete(resSchema),

Expand Down
Loading
Loading