-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add bandwidth server resource (#475)
Closes #474 * add bandwitdh server resource * add tests for the bandwitdh server resource * specify the bandwitdh server resource in provider * add examples for the bandwidth server resource * fix typo * fix function name * generate docs for bandwidth server resource * refactor: Small fixes to the added resource * refactor: Add a helper for KeyEnabled * fix: Resolve merge conflict --------- Co-authored-by: Vaerh <vaerh@tutanota.com>
- Loading branch information
1 parent
f672534
commit d98ce0f
Showing
17 changed files
with
182 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 generated by tfplugindocs --> | ||
## 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 . | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
terraform import routeros_tool_bandwidth_server.test . |
6 changes: 6 additions & 0 deletions
6
examples/resources/routeros_tool_bandwidth_server/resource.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
resource "routeros_tool_bandwidth_test_server" "test" { | ||
enabled = true | ||
authenticate = false | ||
max_sessions = 100 | ||
allocate_udp_ports_from = 2000 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters