Merge pull request #2008 from dupuy/secgrp-delta-remove-then-add

remove security groups (by name) before adding security groups (by id)
This commit is contained in:
Paul Hinze 2015-09-24 14:14:48 -05:00
commit 50b8161da1
1 changed files with 8 additions and 7 deletions

View File

@ -610,13 +610,6 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e
log.Printf("[DEBUG] Security groups to remove: %v", secgroupsToRemove) log.Printf("[DEBUG] Security groups to remove: %v", secgroupsToRemove)
for _, g := range secgroupsToAdd.List() {
err := secgroups.AddServerToGroup(computeClient, d.Id(), g.(string)).ExtractErr()
if err != nil {
return fmt.Errorf("Error adding security group to OpenStack server (%s): %s", d.Id(), err)
}
log.Printf("[DEBUG] Added security group (%s) to instance (%s)", g.(string), d.Id())
}
for _, g := range secgroupsToRemove.List() { for _, g := range secgroupsToRemove.List() {
err := secgroups.RemoveServerFromGroup(computeClient, d.Id(), g.(string)).ExtractErr() err := secgroups.RemoveServerFromGroup(computeClient, d.Id(), g.(string)).ExtractErr()
@ -634,6 +627,14 @@ func resourceComputeInstanceV2Update(d *schema.ResourceData, meta interface{}) e
log.Printf("[DEBUG] Removed security group (%s) from instance (%s)", g.(string), d.Id()) log.Printf("[DEBUG] Removed security group (%s) from instance (%s)", g.(string), d.Id())
} }
} }
for _, g := range secgroupsToAdd.List() {
err := secgroups.AddServerToGroup(computeClient, d.Id(), g.(string)).ExtractErr()
if err != nil {
return fmt.Errorf("Error adding security group to OpenStack server (%s): %s", d.Id(), err)
}
log.Printf("[DEBUG] Added security group (%s) to instance (%s)", g.(string), d.Id())
}
} }
if d.HasChange("admin_pass") { if d.HasChange("admin_pass") {