Skip to content

Commit

Permalink
Add DiffSuppressFunc for op_mode and aggregate_num_ports
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaspence committed Mar 8, 2023
1 parent bf08789 commit 28b6de4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 13 additions & 0 deletions internal/provider/resource_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -90,12 +91,24 @@ func resourceDevice() *schema.Resource {
Optional: true,
Default: "switch",
ValidateFunc: validation.StringInSlice([]string{"switch", "mirror", "aggregate"}, false),
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if old == "" && new == "switch" {
return true
}
return false
},
},
"aggregate_num_ports": {
Description: "Number of ports in the aggregate.",
Type: schema.TypeInt,
Optional: true,
ValidateFunc: validation.IntBetween(2, 8),
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
if old == strconv.Itoa(0) && new == "" {
return true
}
return false
},
},
},
},
Expand Down
4 changes: 3 additions & 1 deletion internal/provider/resource_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,14 @@ func TestAccDevice_switch_portOverrides(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "port_override.1.number", "1"),
resource.TestCheckResourceAttr(resourceName, "port_override.1.name", "Port 1"),
resource.TestCheckResourceAttr(resourceName, "port_override.1.port_profile_id", ""),
resource.TestCheckResourceAttr(resourceName, "port_override.1.op_mode", "switch"),
//resource.TestCheckResourceAttr(resourceName, "port_override.1.op_mode", "switch"),
resource.TestCheckResourceAttr(resourceName, "port_override.1.aggregate_num_ports", ""),

resource.TestCheckResourceAttr(resourceName, "port_override.2.number", "2"),
resource.TestCheckResourceAttr(resourceName, "port_override.2.name", "Port 2"),
//resource.TestCheckResourceAttr(resourceName, "port_override.2.port_profile_id", ""),
resource.TestCheckResourceAttr(resourceName, "port_override.2.op_mode", "switch"),
resource.TestCheckResourceAttr(resourceName, "port_override.2.aggregate_num_ports", ""),
),
},
{
Expand Down

0 comments on commit 28b6de4

Please sign in to comment.