Skip to content

Commit 87d48e0

Browse files
authored
feat: add DiffSuppressFunc for network_adapters on r/host_virtual_switch (#2388)
Signed-off-by: Stoyan Zhelyazkov <[email protected]>
1 parent 751737b commit 87d48e0

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

vsphere/host_virtual_switch_structure.go

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ func schemaHostVirtualSwitchBondBridge() map[string]*schema.Schema {
5858

5959
// HostVirtualSwitchBondBridge
6060
"network_adapters": {
61-
Type: schema.TypeList,
62-
Required: true,
63-
Description: "The list of network adapters to bind to this virtual switch.",
64-
Elem: &schema.Schema{Type: schema.TypeString},
61+
Type: schema.TypeList,
62+
Required: true,
63+
Description: "The list of network adapters to bind to this virtual switch.",
64+
Elem: &schema.Schema{Type: schema.TypeString},
65+
DiffSuppressFunc: networkAdaptersSupressDiff,
6566
},
6667
}
6768
}
@@ -199,3 +200,39 @@ func splitHostVirtualSwitchID(raw string) (string, string, error) {
199200
func virtualSwitchIDsFromResourceID(d *schema.ResourceData) (string, string, error) {
200201
return splitHostVirtualSwitchID(d.Id())
201202
}
203+
204+
// networkAdaptersSupressDiff checks if the 'network_adapters' set has changed, ignoring and difference
205+
// in the order of elements.
206+
func networkAdaptersSupressDiff(_, _, _ string, d *schema.ResourceData) bool {
207+
o, n := d.GetChange("network_adapters")
208+
oldAdapters := o.([]interface{})
209+
newAdapters := n.([]interface{})
210+
211+
if len(oldAdapters) != len(newAdapters) {
212+
return false
213+
}
214+
215+
for _, oldAdapter := range oldAdapters {
216+
if found := isAdapterFound(oldAdapter, newAdapters); !found {
217+
return false
218+
}
219+
}
220+
221+
for _, newAdapter := range newAdapters {
222+
if found := isAdapterFound(newAdapter, oldAdapters); !found {
223+
return false
224+
}
225+
}
226+
227+
return true
228+
}
229+
230+
func isAdapterFound(adapter interface{}, set []interface{}) bool {
231+
for _, v := range set {
232+
if adapter == v {
233+
return true
234+
}
235+
}
236+
237+
return false
238+
}

0 commit comments

Comments
 (0)