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

fix: do not set default value for netmask in mikrotik_dhcp_server_network #220

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
2 changes: 1 addition & 1 deletion docs/resources/dhcp_server_network.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ resource "mikrotik_dhcp_server_network" "default" {
- `comment` (String)
- `dns_server` (String) The DHCP client will use these as the default DNS servers.
- `gateway` (String) The default gateway to be used by DHCP Client. Default: `0.0.0.0`.
- `netmask` (String) The actual network mask to be used by DHCP client. If set to '0' - netmask from network address will be used. Default: `0`.
- `netmask` (String) The actual network mask to be used by DHCP client. If set to '0' - netmask from network address will be used.

### Read-Only

Expand Down
1 change: 0 additions & 1 deletion mikrotik/resource_dhcp_server_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func (s *dhcpServerNetwork) Schema(_ context.Context, _ resource.SchemaRequest,
"netmask": schema.StringAttribute{
Optional: true,
Computed: true,
Default: stringdefault.StaticString("0"),
Description: "The actual network mask to be used by DHCP client. If set to '0' - netmask from network address will be used.",
},
"gateway": schema.StringAttribute{
Expand Down
49 changes: 47 additions & 2 deletions mikrotik/resource_dhcp_server_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import (
)

func TestDhcpServerNetwork_basic(t *testing.T) {

resourceName := "mikrotik_dhcp_server_network.testacc"

netmask := "24"
address := "10.10.10.0/" + netmask
gateway := "10.10.10.2"
Expand Down Expand Up @@ -50,6 +48,53 @@ func TestDhcpServerNetwork_basic(t *testing.T) {
})
}

func TestDhcpServerNetwork_incompleteFieldsSet(t *testing.T) {
resourceName := "mikrotik_dhcp_server_network.testacc"
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
CheckDestroy: testAccCheckDhcpServerNetworkDestroy,
Steps: []resource.TestStep{
{
Config: `
resource mikrotik_dhcp_server_network "testacc" {
address = "10.10.10.0/24"
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
testAccDhcpServerNetworkExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "address", "10.10.10.0/24"),
),
},
{
Config: `
resource mikrotik_dhcp_server_network "testacc" {
address = "10.10.10.0/24"
netmask = "24"
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
testAccDhcpServerNetworkExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "address", "10.10.10.0/24"),
resource.TestCheckResourceAttr(resourceName, "netmask", "24"),
),
},
{
Config: `
resource mikrotik_dhcp_server_network "testacc" {
address = "10.10.10.0/24"
}
`,
Check: resource.ComposeAggregateTestCheckFunc(
testAccDhcpServerNetworkExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "address", "10.10.10.0/24"),
resource.TestCheckResourceAttr(resourceName, "netmask", "24"),
),
},
},
})
}

func testAccDhcpServerNetwork(address, netmask, gateway, dns_server, comment string) string {
return fmt.Sprintf(`
resource mikrotik_dhcp_server_network "testacc" {
Expand Down
Loading