diff --git a/docs/resources/tool_bandwidth_server.md b/docs/resources/tool_bandwidth_server.md new file mode 100644 index 00000000..ad76337f --- /dev/null +++ b/docs/resources/tool_bandwidth_server.md @@ -0,0 +1,32 @@ +# routeros_tool_bandwidth_server (Resource) + + +## Example Usage +```terraform +resource "routeros_tool_bandwidth_test_server" "test" { + enabled = true + authenticate = false + max_sessions = 100 + allocate_udp_ports_from = 2000 +} +``` + + +## Schema + +### Optional + +- `allocate_udp_ports_from ` (Boolean) Beginning of UDP port range. +- `authenticate` (Boolean) Communicate only with authenticated clients. +- `enabled` (Boolean) Defines whether bandwidth server is enabled or not. +- `max_sessions ` (Number) Maximal simultaneous test count. + +### Read-Only + +- `id` (String) The ID of this resource. + +## Import +Import is supported using the following syntax: +```shell +terraform import routeros_tool_bandwidth_server.test . +``` diff --git a/examples/resources/routeros_tool_bandwidth_server/import.sh b/examples/resources/routeros_tool_bandwidth_server/import.sh new file mode 100644 index 00000000..3371890d --- /dev/null +++ b/examples/resources/routeros_tool_bandwidth_server/import.sh @@ -0,0 +1 @@ +terraform import routeros_tool_bandwidth_server.test . \ No newline at end of file diff --git a/examples/resources/routeros_tool_bandwidth_server/resource.tf b/examples/resources/routeros_tool_bandwidth_server/resource.tf new file mode 100644 index 00000000..f710cb4e --- /dev/null +++ b/examples/resources/routeros_tool_bandwidth_server/resource.tf @@ -0,0 +1,6 @@ +resource "routeros_tool_bandwidth_test_server" "test" { + enabled = true + authenticate = false + max_sessions = 100 + allocate_udp_ports_from = 2000 +} \ No newline at end of file diff --git a/routeros/provider.go b/routeros/provider.go index 8d41a672..b10e7b4e 100644 --- a/routeros/provider.go +++ b/routeros/provider.go @@ -171,21 +171,23 @@ func Provider() *schema.Provider { "routeros_wireguard_peer": ResourceInterfaceWireguardPeer(), // System Objects - "routeros_ip_cloud": ResourceIpCloud(), - "routeros_ip_cloud_advanced": ResourceIpCloudAdvanced(), - "routeros_system_certificate": ResourceSystemCertificate(), - "routeros_certificate_scep_server": ResourceCertificateScepServer(), - "routeros_system_clock": ResourceSystemClock(), - "routeros_system_identity": ResourceSystemIdentity(), - "routeros_system_logging": ResourceSystemLogging(), - "routeros_system_ntp_client": ResourceSystemNtpClient(), - "routeros_system_ntp_server": ResourceSystemNtpServer(), - "routeros_system_scheduler": ResourceSystemScheduler(), - "routeros_system_script": ResourceSystemScript(), - "routeros_system_user": ResourceUser(), - "routeros_system_user_aaa": ResourceUserAaa(), - "routeros_system_user_group": ResourceUserGroup(), - "routeros_system_user_settings": ResourceSystemUserSettings(), + "routeros_ip_cloud": ResourceIpCloud(), + "routeros_ip_cloud_advanced": ResourceIpCloudAdvanced(), + "routeros_system_certificate": ResourceSystemCertificate(), + "routeros_system_certificate_scep_server": ResourceCertificateScepServer(), + "routeros_certificate_scep_server": ResourceCertificateScepServer(), + "routeros_system_clock": ResourceSystemClock(), + "routeros_system_identity": ResourceSystemIdentity(), + "routeros_system_logging": ResourceSystemLogging(), + "routeros_system_logging_action": ResourceSystemLoggingAction(), + "routeros_system_ntp_client": ResourceSystemNtpClient(), + "routeros_system_ntp_server": ResourceSystemNtpServer(), + "routeros_system_scheduler": ResourceSystemScheduler(), + "routeros_system_script": ResourceSystemScript(), + "routeros_system_user": ResourceUser(), + "routeros_system_user_aaa": ResourceUserAaa(), + "routeros_system_user_group": ResourceUserGroup(), + "routeros_system_user_settings": ResourceSystemUserSettings(), // Aliases for system objects to retain compatibility between original and fork "routeros_identity": ResourceSystemIdentity(), @@ -245,6 +247,7 @@ func Provider() *schema.Provider { "routeros_move_items": ResourceMoveItems(), // Tools + "routeros_tool_bandwidth_server": ResourceToolBandwidthServer(), "routeros_tool_mac_server": ResourceToolMacServer(), "routeros_tool_mac_server_winbox": ResourceToolMacServerWinBox(), diff --git a/routeros/provider_schema_helpers.go b/routeros/provider_schema_helpers.go index 8521c907..a2e7e28b 100644 --- a/routeros/provider_schema_helpers.go +++ b/routeros/provider_schema_helpers.go @@ -35,6 +35,7 @@ const ( KeyDisabled = "disabled" KeyDontFragment = "dont_fragment" KeyDscp = "dscp" + KeyEnabled = "enabled" KeyFilter = "filter" KeyInactive = "inactive" KeyInterface = "interface" @@ -154,6 +155,16 @@ func PropName(description string) *schema.Schema { } } +// PropEnabled +func PropEnabled(description string) *schema.Schema { + return &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Description: description, + DiffSuppressFunc: AlwaysPresentNotUserProvided, + } +} + // PropMacAddress func PropMacAddressRw(description string, required bool) *schema.Schema { mac := &schema.Schema{ diff --git a/routeros/resource_capsman_manager.go b/routeros/resource_capsman_manager.go index 82e54214..7834e4fb 100644 --- a/routeros/resource_capsman_manager.go +++ b/routeros/resource_capsman_manager.go @@ -37,11 +37,7 @@ func ResourceCapsManManager() *schema.Resource { Default: "none", Description: "Device certificate.", }, - "enabled": { - Type: schema.TypeBool, - Optional: true, - Description: "Disable or enable CAPsMAN functionality.", - }, + KeyEnabled: PropEnabled("Disable or enable CAPsMAN functionality."), "generated_ca_certificate": { Type: schema.TypeString, Computed: true, diff --git a/routeros/resource_interface_wireless_cap.go b/routeros/resource_interface_wireless_cap.go index d8336459..8669a45d 100644 --- a/routeros/resource_interface_wireless_cap.go +++ b/routeros/resource_interface_wireless_cap.go @@ -69,11 +69,7 @@ func ResourceInterfaceWirelessCap() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, Description: "List of interfaces over which CAP should attempt to discover CAPs Manager.", }, - "enabled": { - Type: schema.TypeBool, - Optional: true, - Description: "Disable or enable the CAP functionality.", - }, + KeyEnabled: PropEnabled("Disable or enable the CAP functionality."), "interfaces": { Type: schema.TypeSet, Optional: true, diff --git a/routeros/resource_ip_upnp.go b/routeros/resource_ip_upnp.go index 4bb274c4..1d67e20d 100644 --- a/routeros/resource_ip_upnp.go +++ b/routeros/resource_ip_upnp.go @@ -19,11 +19,7 @@ func ResourceUPNPSettings() *schema.Resource { "unwanted in UPnP deployments which the standard was not designed for (it was designed mostly for " + "home users to establish their own local networks), you can disable this behavior", }, - "enabled": { - Type: schema.TypeBool, - Optional: true, - Description: "Enable UPnP service.", - }, + KeyEnabled: PropEnabled("Enable UPnP service."), "show_dummy_rule": { Type: schema.TypeBool, Optional: true, diff --git a/routeros/resource_ovpn_server.go b/routeros/resource_ovpn_server.go index 1595b061..10fe096d 100644 --- a/routeros/resource_ovpn_server.go +++ b/routeros/resource_ovpn_server.go @@ -69,11 +69,7 @@ func ResourceOpenVPNServer() *schema.Resource { Optional: true, Description: "Specifies if IPv6 IP tunneling mode should be possible with this OVPN server.", }, - "enabled": { - Type: schema.TypeBool, - Optional: true, - Description: "Defines whether the OVPN server is enabled or not.", - }, + KeyEnabled: PropEnabled("Defines whether the OVPN server is enabled or not."), "ipv6_prefix_len": { Type: schema.TypeInt, Optional: true, diff --git a/routeros/resource_snmp.go b/routeros/resource_snmp.go index 6bcf8356..2cdbd6c0 100644 --- a/routeros/resource_snmp.go +++ b/routeros/resource_snmp.go @@ -32,11 +32,7 @@ func ResourceSNMP() *schema.Resource { Optional: true, Description: "Contact information.", }, - "enabled": { - Type: schema.TypeBool, - Required: true, - Description: "Used to disable/enable SNMP service", - }, + KeyEnabled: PropEnabled("Used to disable/enable SNMP service"), "engine_id": { Type: schema.TypeString, Computed: true, diff --git a/routeros/resource_system_ntp_client.go b/routeros/resource_system_ntp_client.go index f61fb7db..95860419 100644 --- a/routeros/resource_system_ntp_client.go +++ b/routeros/resource_system_ntp_client.go @@ -25,12 +25,7 @@ func ResourceSystemNtpClient() *schema.Resource { MetaResourcePath: PropResourcePath("/system/ntp/client"), MetaId: PropId(Id), - "enabled": { - Type: schema.TypeBool, - Optional: true, - Description: "Enable NTP client.", - DiffSuppressFunc: AlwaysPresentNotUserProvided, - }, + KeyEnabled: PropEnabled("Enable NTP client."), "freq_drift": { Type: schema.TypeString, Computed: true, diff --git a/routeros/resource_system_ntp_server.go b/routeros/resource_system_ntp_server.go index 6c18aa19..169aa501 100644 --- a/routeros/resource_system_ntp_server.go +++ b/routeros/resource_system_ntp_server.go @@ -43,12 +43,7 @@ func ResourceSystemNtpServer() *schema.Resource { Optional: true, Description: "Set broadcast address to use for NTP server broadcast mode.", }, - "enabled": { - Type: schema.TypeBool, - Optional: true, - Description: "Enable NTP server.", - DiffSuppressFunc: AlwaysPresentNotUserProvided, - }, + KeyEnabled: PropEnabled("Enable NTP server."), "local_clock_stratum": { Type: schema.TypeInt, Optional: true, diff --git a/routeros/resource_tool_bandwidth_server.go b/routeros/resource_tool_bandwidth_server.go new file mode 100644 index 00000000..0c936f63 --- /dev/null +++ b/routeros/resource_tool_bandwidth_server.go @@ -0,0 +1,58 @@ +package routeros + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +/* +{ + "allocate-udp-ports-from": "2000", + "authenticate": "true", + "enabled": "true", + "max-sessions": "100" +} +*/ + +// https://help.mikrotik.com/docs/display/ROS/Bandwidth+Test +func ResourceToolBandwidthServer() *schema.Resource { + resSchema := map[string]*schema.Schema{ + MetaResourcePath: PropResourcePath("/tool/bandwidth-server"), + MetaId: PropId(Id), + + "allocate_udp_ports_from": { + Type: schema.TypeInt, + Optional: true, + Description: "Beginning of UDP port range.", + ValidateFunc: validation.IntBetween(1000, 65535), + DiffSuppressFunc: AlwaysPresentNotUserProvided, + }, + "authenticate": { + Type: schema.TypeBool, + Optional: true, + Description: "Communicate only with authenticated clients.", + DiffSuppressFunc: AlwaysPresentNotUserProvided, + }, + KeyEnabled: PropEnabled("Defines whether bandwidth server is enabled or not."), + "max_sessions": { + Type: schema.TypeInt, + Optional: true, + Description: "Maximal simultaneous test count.", + ValidateFunc: validation.IntBetween(1, 1000), + DiffSuppressFunc: AlwaysPresentNotUserProvided, + }, + } + + return &schema.Resource{ + CreateContext: DefaultSystemCreate(resSchema), + ReadContext: DefaultSystemRead(resSchema), + UpdateContext: DefaultSystemUpdate(resSchema), + DeleteContext: DefaultSystemDelete(resSchema), + + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Schema: resSchema, + } +} diff --git a/routeros/resource_tool_bandwidth_server_test.go b/routeros/resource_tool_bandwidth_server_test.go new file mode 100644 index 00000000..9fd1a3eb --- /dev/null +++ b/routeros/resource_tool_bandwidth_server_test.go @@ -0,0 +1,62 @@ +package routeros + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" +) + +const testToolsBandwidthServer = "routeros_tool_bandwidth_server.test" + +func TestAccToolsBandwidthServerTest_basic(t *testing.T) { + for _, name := range testNames { + t.Run(name, func(t *testing.T) { + resource.Test(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + testSetTransportEnv(t, name) + }, + ProviderFactories: testAccProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccToolsBandwidthServerConfig_none(), + Check: resource.ComposeTestCheckFunc( + testResourcePrimaryInstanceId(testToolsBandwidthServer), + resource.TestCheckResourceAttr(testToolsBandwidthServer, "enabled", "false"), + ), + }, + { + Config: testAccToolsBandwidthServerConfig_complex(), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(testToolsBandwidthServer, "enabled", "true"), + resource.TestCheckResourceAttr(testToolsBandwidthServer, "authenticate", "false"), + resource.TestCheckResourceAttr(testToolsBandwidthServer, "max_sessions", "100"), + resource.TestCheckResourceAttr(testToolsBandwidthServer, "allocate_udp_ports_from", "2000"), + ), + }, + }, + }) + }) + } +} + +func testAccToolsBandwidthServerConfig_none() string { + return providerConfig + ` + +resource "routeros_tool_bandwidth_server" "test" { + enabled = false +} +` +} + +func testAccToolsBandwidthServerConfig_complex() string { + return providerConfig + ` + +resource "routeros_tool_bandwidth_server" "test" { + enabled = true + authenticate = false + max_sessions = 100 + allocate_udp_ports_from = 2000 +} +` +} diff --git a/routeros/resource_user_manager_settings.go b/routeros/resource_user_manager_settings.go index f84ced5c..518a8eef 100644 --- a/routeros/resource_user_manager_settings.go +++ b/routeros/resource_user_manager_settings.go @@ -41,12 +41,7 @@ func ResourceUserManagerSettings() *schema.Resource { Default: "none", Description: "Certificate for use in EAP TLS-type authentication methods.", }, - "enabled": { - Type: schema.TypeBool, - Optional: true, - Default: false, - Description: "An option whether the User Manager functionality is enabled.", - }, + KeyEnabled: PropEnabled("An option whether the User Manager functionality is enabled."), "use_profiles": { Type: schema.TypeBool, Optional: true, diff --git a/routeros/resource_wifi_cap.go b/routeros/resource_wifi_cap.go index c6aee38d..1fbaaf46 100644 --- a/routeros/resource_wifi_cap.go +++ b/routeros/resource_wifi_cap.go @@ -28,7 +28,7 @@ func ResourceWifiCap() *schema.Resource { "caps_man_addresses": { Type: schema.TypeList, Optional: true, - Elem: &schema.Schema{ + Elem: &schema.Schema{ Type: schema.TypeString, ValidateFunc: validation.IsIPAddress, }, @@ -57,11 +57,7 @@ func ResourceWifiCap() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, Description: "List of interfaces over which CAP should attempt to discover CAPs Manager.", }, - "enabled": { - Type: schema.TypeBool, - Optional: true, - Description: "Disable or enable the CAP functionality.", - }, + KeyEnabled: PropEnabled("Disable or enable the CAP functionality."), "lock_to_caps_man": { Type: schema.TypeBool, Optional: true, diff --git a/routeros/resource_wifi_capsman.go b/routeros/resource_wifi_capsman.go index 8c5815a2..9d1eddd0 100644 --- a/routeros/resource_wifi_capsman.go +++ b/routeros/resource_wifi_capsman.go @@ -35,11 +35,7 @@ func ResourceWifiCapsman() *schema.Resource { Optional: true, Description: "Device certificate.", }, - "enabled": { - Type: schema.TypeBool, - Optional: true, - Description: "Disable or enable CAPsMAN functionality.", - }, + KeyEnabled: PropEnabled("Disable or enable CAPsMAN functionality."), "generated_ca_certificate": { Type: schema.TypeString, Computed: true,