Skip to content

Commit 519fff0

Browse files
committed
Avoid diffs due to order of elements returned by the controller
The network and member resource use a couple of settings which could be defined multiple times. For example: the assigned ips on a member could change the order, while the semantic means the same. The provider was using a `schema.ListType`, which according to the documentation is an *ordered* list of elements, where the order matter. On those resource seetings, the order is not relevant, as they are sematically equivalent. There is a `schema.SetType` which provides an *unordered* collection of settings, and grants the same order given the same settings. This commit changes the schema of those resources to use `schema.SetType` instead of `schema.ListType` to avoid diff loops depending on the sorting of the response from the API.
1 parent d577564 commit 519fff0

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

zerotier/resource_zerotier_member.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func resourceZeroTierMember() *schema.Resource {
6868
},
6969
},
7070
"capabilities": {
71-
Type: schema.TypeList,
71+
Type: schema.TypeSet,
7272
Optional: true,
7373
Elem: &schema.Schema{
7474
Type: schema.TypeInt,
@@ -143,7 +143,7 @@ func memberFromResourceData(d *schema.ResourceData) (*Member, error) {
143143
}
144144
tagTuples = append(tagTuples, []int{i, val.(int)})
145145
}
146-
capsRaw := d.Get("capabilities").([]interface{})
146+
capsRaw := d.Get("capabilities").(*schema.Set).List()
147147
caps := make([]int, len(capsRaw))
148148
for i := range capsRaw {
149149
caps[i] = capsRaw[i].(int)

zerotier/resource_zerotier_network.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func resourceZeroTierNetwork() *schema.Resource {
6363
Default: true,
6464
},
6565
"route": &schema.Schema{
66-
Type: schema.TypeList,
66+
Type: schema.TypeSet,
6767
Optional: true,
6868
Elem: route(),
6969
},
@@ -113,7 +113,7 @@ func resourceNetworkExists(d *schema.ResourceData, m interface{}) (b bool, e err
113113
}
114114

115115
func fromResourceData(d *schema.ResourceData) (*Network, error) {
116-
routesRaw := d.Get("route").([]interface{})
116+
routesRaw := d.Get("route").(*schema.Set).List()
117117
var routes []Route
118118
for _, raw := range routesRaw {
119119
r := raw.(map[string]interface{})

0 commit comments

Comments
 (0)