Skip to content

Commit

Permalink
avoid unnecessary diffs in members
Browse files Browse the repository at this point in the history
See issue #17

Turn Lists into Sets, so the order doesn't matter
  • Loading branch information
laduke committed Oct 18, 2022
1 parent 231cfa4 commit 80dafac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 8 additions & 0 deletions pkg/zerotier/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func fetchStringList(d *schema.ResourceData, attr string) *[]string {
return toStringList(d.Get(attr).([]interface{})).(*[]string)
}

func fetchStringSet(d *schema.ResourceData, attr string) *[]string {
return toStringList(d.Get(attr).(*schema.Set).List()).(*[]string)
}

func toStringList(i interface{}) interface{} {
ray := &[]string{}
for _, x := range i.([]interface{}) {
Expand All @@ -56,6 +60,10 @@ func fetchIntList(d *schema.ResourceData, attr string) *[]int {
return toIntList(d.Get(attr).([]interface{})).(*[]int)
}

func fetchIntSet(d *schema.ResourceData, attr string) *[]int {
return toIntList(d.Get(attr).(*schema.Set).List()).(*[]int)
}

func fetchTags(d []interface{}) *[][]int {
tags := [][]int{}

Expand Down
12 changes: 6 additions & 6 deletions pkg/zerotier/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ var MemberSchema = map[string]*schema.Schema{
Description: "Exempt this member from the IP auto assignment pool on a Network",
},
"ip_assignments": {
Type: schema.TypeList,
Type: schema.TypeSet,
Computed: true,
Optional: true,
Elem: &schema.Schema{
Expand All @@ -68,7 +68,7 @@ var MemberSchema = map[string]*schema.Schema{
Description: "List of IP address assignments",
},
"capabilities": {
Type: schema.TypeList,
Type: schema.TypeSet,
Computed: true,
Optional: true,
Elem: &schema.Schema{
Expand All @@ -77,7 +77,7 @@ var MemberSchema = map[string]*schema.Schema{
Description: "List of network capabilities",
},
"tags": {
Type: schema.TypeList,
Type: schema.TypeSet,
Computed: true,
Optional: true,
Elem: &schema.Schema{
Expand All @@ -102,9 +102,9 @@ func toMember(d *schema.ResourceData) *spec.Member {
Authorized: boolPtr(d.Get("authorized").(bool)),
ActiveBridge: boolPtr(d.Get("allow_ethernet_bridging").(bool)),
NoAutoAssignIps: boolPtr(d.Get("no_auto_assign_ips").(bool)),
Capabilities: fetchIntList(d, "capabilities"),
IpAssignments: fetchStringList(d, "ip_assignments"),
Tags: fetchTags(d.Get("tags").([]interface{})),
Capabilities: fetchIntSet(d, "capabilities"),
IpAssignments: fetchStringSet(d, "ip_assignments"),
Tags: fetchTags(d.Get("tags").(*schema.Set).List()),
},
}
}
Expand Down

0 comments on commit 80dafac

Please sign in to comment.