Merge pull request #3651 from Sheile/ignore-sg-order

provider/openstack: Ignore order of security_groups in instance
This commit is contained in:
Joe Topjian 2015-10-30 22:35:06 +09:00
commit beab5619e2
1 changed files with 5 additions and 5 deletions

View File

@ -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,
@ -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)
@ -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)