Skip to content

Commit

Permalink
Merge pull request #3651 from Sheile/ignore-sg-order
Browse files Browse the repository at this point in the history
provider/openstack: Ignore order of security_groups in instance
  • Loading branch information
jtopjian committed Oct 30, 2015
2 parents ef0990f + 59828de commit beab561
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ func resourceComputeInstanceV2() *schema.Resource {
},
},
"security_groups": &schema.Schema{
Type: schema.TypeList,
Type: schema.TypeSet,
Optional: true,
ForceNew: false,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
"availability_zone": &schema.Schema{
Type: schema.TypeString,
Expand Down Expand Up @@ -600,9 +601,8 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e

if d.HasChange("security_groups") {
oldSGRaw, newSGRaw := d.GetChange("security_groups")
oldSGSlice, newSGSlice := oldSGRaw.([]interface{}), newSGRaw.([]interface{})
oldSGSet := schema.NewSet(func(v interface{}) int { return hashcode.String(v.(string)) }, oldSGSlice)
newSGSet := schema.NewSet(func(v interface{}) int { return hashcode.String(v.(string)) }, newSGSlice)
oldSGSet := oldSGRaw.(*schema.Set)
newSGSet := newSGRaw.(*schema.Set)
secgroupsToAdd := newSGSet.Difference(oldSGSet)
secgroupsToRemove := oldSGSet.Difference(newSGSet)

Expand Down Expand Up @@ -807,7 +807,7 @@ func ServerV2StateRefreshFunc(client *gophercloud.ServiceClient, instanceID stri
}

func resourceInstanceSecGroupsV2(d *schema.ResourceData) []string {
rawSecGroups := d.Get("security_groups").([]interface{})
rawSecGroups := d.Get("security_groups").(*schema.Set).List()
secgroups := make([]string, len(rawSecGroups))
for i, raw := range rawSecGroups {
secgroups[i] = raw.(string)
Expand Down

0 comments on commit beab561

Please sign in to comment.