Skip to content

Commit a086b8e

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 ff1ffb1 commit a086b8e

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
@@ -83,7 +83,7 @@ func resourceZeroTierMember() *schema.Resource {
8383
Computed: true,
8484
},
8585
"capabilities": {
86-
Type: schema.TypeList,
86+
Type: schema.TypeSet,
8787
Optional: true,
8888
Elem: &schema.Schema{
8989
Type: schema.TypeInt,
@@ -158,7 +158,7 @@ func memberFromResourceData(d *schema.ResourceData) (*Member, error) {
158158
}
159159
tagTuples = append(tagTuples, []int{i, val.(int)})
160160
}
161-
capsRaw := d.Get("capabilities").([]interface{})
161+
capsRaw := d.Get("capabilities").(*schema.Set).List()
162162
caps := make([]int, len(capsRaw))
163163
for i := range capsRaw {
164164
caps[i] = capsRaw[i].(int)

zerotier/resource_zerotier_network.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func resourceZeroTierNetwork() *schema.Resource {
8484
Default: true,
8585
},
8686
"route": &schema.Schema{
87-
Type: schema.TypeList,
87+
Type: schema.TypeSet,
8888
Optional: true,
8989
Elem: route(),
9090
},
@@ -134,7 +134,7 @@ func resourceNetworkExists(d *schema.ResourceData, m interface{}) (b bool, e err
134134
}
135135

136136
func fromResourceData(d *schema.ResourceData) (*Network, error) {
137-
routesRaw := d.Get("route").([]interface{})
137+
routesRaw := d.Get("route").(*schema.Set).List()
138138
var routes []Route
139139
for _, raw := range routesRaw {
140140
r := raw.(map[string]interface{})

0 commit comments

Comments
 (0)