-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
397 additions
and
1 deletion.
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
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,42 @@ | ||
# routeros_ip_dhcp_server_option (Resource) | ||
Creates a DHCP lease on the mikrotik device. | ||
|
||
## Example Usage | ||
```terraform | ||
resource "routeros_ip_dhcp_server_option" "jumbo_frame_opt" { | ||
code = 77 | ||
name = "jumbo-mtu-opt" | ||
value = "0x2336" | ||
} | ||
resource "routeros_ip_dhcp_server_option" "tftp_option" { | ||
code = 66 | ||
name = "tftpserver-66" | ||
value = "s'10.10.10.22'" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `code` (Number) The number of the DHCP option | ||
- `name` (String) The name of the DHCP option | ||
- `value` (String) The value with formatting using Mikrotik settings https://wiki.mikrotik.com/wiki/Manual:IP/DHCP_Server#DHCP_Options | ||
|
||
### Optional | ||
|
||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
- `raw_value` (String) The computed value of the option as an hex value | ||
|
||
## Import | ||
Import is supported using the following syntax: | ||
```shell | ||
#The ID can be found via API or the terminal | ||
#The command for the terminal is -> :put [/ip/dhcp-server/option/get [print show-ids]] | ||
terraform import routeros_ip_dhcp_server_option.tftp_option "*1" | ||
``` |
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,45 @@ | ||
# routeros_ip_dhcp_server_option_set (Resource) | ||
Creates a DHCP lease on the mikrotik device. | ||
|
||
## Example Usage | ||
```terraform | ||
resource "routeros_ip_dhcp_server_option" "jumbo_frame_opt" { | ||
code = 77 | ||
name = "jumbo-mtu-opt" | ||
value = "0x2336" | ||
} | ||
resource "routeros_ip_dhcp_server_option" "tftp_option" { | ||
code = 66 | ||
name = "tftpserver-66" | ||
value = "s'10.10.10.22'" | ||
} | ||
resource "routeros_ip_dhcp_server_option_set" "lan_option_set" { | ||
name = "lan-option-set" | ||
options = join(",", [routeros_ip_dhcp_server_option.jumbo_frame_opt.name, routeros_ip_dhcp_server_option.tftp_option.name]) | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `name` (String) The name of the DHCP option | ||
- `options` (String) The comma sepparated list of options | ||
|
||
### Optional | ||
|
||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
|
||
## Import | ||
Import is supported using the following syntax: | ||
```shell | ||
#The ID can be found via API or the terminal | ||
#The command for the terminal is -> :put [/ip/dhcp-server/option/sets/get [print show-ids]] | ||
terraform import routeros_ip_dhcp_server_option_set.lan_option_set "*1" | ||
``` |
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,3 @@ | ||
#The ID can be found via API or the terminal | ||
#The command for the terminal is -> :put [/ip/dhcp-server/option/get [print show-ids]] | ||
terraform import routeros_ip_dhcp_server_option.tftp_option "*1" |
12 changes: 12 additions & 0 deletions
12
examples/resources/routeros_ip_dhcp_server_option/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,12 @@ | ||
|
||
resource "routeros_ip_dhcp_server_option" "jumbo_frame_opt" { | ||
code = 77 | ||
name = "jumbo-mtu-opt" | ||
value = "0x2336" | ||
} | ||
|
||
resource "routeros_ip_dhcp_server_option" "tftp_option" { | ||
code = 66 | ||
name = "tftpserver-66" | ||
value = "s'10.10.10.22'" | ||
} |
3 changes: 3 additions & 0 deletions
3
examples/resources/routeros_ip_dhcp_server_option_set/import.sh
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,3 @@ | ||
#The ID can be found via API or the terminal | ||
#The command for the terminal is -> :put [/ip/dhcp-server/option/sets/get [print show-ids]] | ||
terraform import routeros_ip_dhcp_server_option_set.lan_option_set "*1" |
17 changes: 17 additions & 0 deletions
17
examples/resources/routeros_ip_dhcp_server_option_set/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,17 @@ | ||
|
||
resource "routeros_ip_dhcp_server_option" "jumbo_frame_opt" { | ||
code = 77 | ||
name = "jumbo-mtu-opt" | ||
value = "0x2336" | ||
} | ||
|
||
resource "routeros_ip_dhcp_server_option" "tftp_option" { | ||
code = 66 | ||
name = "tftpserver-66" | ||
value = "s'10.10.10.22'" | ||
} | ||
|
||
resource "routeros_ip_dhcp_server_option_set" "lan_option_set" { | ||
name = "lan-option-set" | ||
options = join(",", [routeros_ip_dhcp_server_option.jumbo_frame_opt.name, routeros_ip_dhcp_server_option.tftp_option.name]) | ||
} |
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,60 @@ | ||
package routeros | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
) | ||
|
||
/* | ||
[ | ||
{ | ||
".id": "*4", | ||
"code": "66", | ||
"name": "optionname", | ||
"raw-value": "00002311", | ||
"value": "0x00002311" | ||
} | ||
] | ||
*/ | ||
|
||
// ResourceDhcpServerOption https://wiki.mikrotik.com/wiki/Manual:IP/DHCP_Server | ||
func ResourceDhcpServerOption() *schema.Resource { | ||
resSchema := map[string]*schema.Schema{ | ||
MetaResourcePath: PropResourcePath("/ip/dhcp-server/option"), | ||
MetaId: PropId(Id), | ||
"code": { | ||
Type: schema.TypeInt, | ||
Required: true, | ||
Description: "The number of the DHCP option", | ||
ValidateFunc: validation.IntBetween(1, 254), | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "The name of the DHCP option", | ||
}, | ||
"raw_value": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The computed value of the option as an hex value", | ||
}, | ||
"value": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "The value with formatting using Mikrotik settings https://wiki.mikrotik.com/wiki/Manual:IP/DHCP_Server#DHCP_Options", | ||
}, | ||
} | ||
return &schema.Resource{ | ||
Description: "Creates a DHCP lease on the mikrotik device.", | ||
|
||
CreateContext: DefaultCreate(resSchema), | ||
ReadContext: DefaultRead(resSchema), | ||
UpdateContext: DefaultUpdate(resSchema), | ||
DeleteContext: DefaultDelete(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,46 @@ | ||
package routeros | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
/* | ||
[ | ||
{ | ||
".id": "*2", | ||
"name": "netboot", | ||
"options": "tftpserver-66,unifi,mtu-jumbo" | ||
} | ||
] | ||
*/ | ||
|
||
// ResourceDhcpServerOption https://wiki.mikrotik.com/wiki/Manual:IP/DHCP_Server | ||
func ResourceDhcpServerOptionSet() *schema.Resource { | ||
resSchema := map[string]*schema.Schema{ | ||
MetaResourcePath: PropResourcePath("/ip/dhcp-server/option/sets"), | ||
MetaId: PropId(Id), | ||
"name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "The name of the DHCP option", | ||
}, | ||
"options": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "The comma sepparated list of options", | ||
}, | ||
} | ||
return &schema.Resource{ | ||
Description: "Creates a DHCP lease on the mikrotik device.", | ||
|
||
CreateContext: DefaultCreate(resSchema), | ||
ReadContext: DefaultRead(resSchema), | ||
UpdateContext: DefaultUpdate(resSchema), | ||
DeleteContext: DefaultDelete(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,73 @@ | ||
package routeros | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-testing/terraform" | ||
) | ||
|
||
const testIpDhcpServerOptionSet = "routeros_ip_dhcp_server_option_set.test_option_set" | ||
|
||
func TestAccIpDhcpServerNetworkOptionSet_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, | ||
CheckDestroy: testCheckResourceDestroy("/ip/dhcp-server/option/sets", "routeros_ip_dhcp_server_option_set"), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccIpDhcpServerOptionSetConfig(), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckIpDhcpServerOptionSetExists(testIpDhcpServerOptionSet), | ||
resource.TestCheckResourceAttr(testIpDhcpServerOptionSet, "name", "test-opt-set"), | ||
resource.TestCheckResourceAttr(testIpDhcpServerOptionSet, "options", "test-opt1,test-opt2"), | ||
), | ||
}, | ||
}, | ||
}) | ||
|
||
}) | ||
} | ||
} | ||
|
||
func testAccCheckIpDhcpServerOptionSetExists(name string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[name] | ||
if !ok { | ||
return fmt.Errorf("not found: %s", name) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("no id is set") | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testAccIpDhcpServerOptionSetConfig() string { | ||
return providerConfig + ` | ||
resource "routeros_ip_dhcp_server_option" "test_option_1" { | ||
code = 77 | ||
name = "test-opt1" | ||
value = "s'10.10.10.22'" | ||
} | ||
resource "routeros_ip_dhcp_server_option" "test_option_2" { | ||
code = 90 | ||
name = "test-opt2" | ||
value = "s'10.10.10.22'" | ||
} | ||
resource "routeros_ip_dhcp_server_option_set" "test_option_set" { | ||
name = "test-opt-set" | ||
options = join(",", [routeros_ip_dhcp_server_option.test_option_1.name, routeros_ip_dhcp_server_option.test_option_2.name]) | ||
} | ||
` | ||
} |
Oops, something went wrong.